#include<iostream> using namespace std; bool samogloska(char a) { if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y') return true; else return false; } bool trigram(char a, char b, char c) { if((samogloska(a) && samogloska(b) && samogloska(c)) || (!samogloska(a) && !samogloska(b) && !samogloska(c))) return true; else return false; } int main() { string input = ""; getline(cin, input); if (input.length() < 3) { cout << "0" << endl; return 0; } long lastTrigram = 0; long long count = 0; for(long i = 0; i <= input.length() - 3; i++) { if(trigram(input[i], input[i+1], input[i+2])) { // cout << "trigram found at " << i << " trigram " << input[i] << input[i+1] << input[i+2] << endl; count += 1; // self if (i > lastTrigram) { // prefixes count += (i - lastTrigram) + (i - lastTrigram) * (input.length() - i - 3); } count += input.length() - i - 3; // postfixes // cout << "count after: " << count << endl; lastTrigram = i+1; } } cout << count << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include<iostream> using namespace std; bool samogloska(char a) { if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y') return true; else return false; } bool trigram(char a, char b, char c) { if((samogloska(a) && samogloska(b) && samogloska(c)) || (!samogloska(a) && !samogloska(b) && !samogloska(c))) return true; else return false; } int main() { string input = ""; getline(cin, input); if (input.length() < 3) { cout << "0" << endl; return 0; } long lastTrigram = 0; long long count = 0; for(long i = 0; i <= input.length() - 3; i++) { if(trigram(input[i], input[i+1], input[i+2])) { // cout << "trigram found at " << i << " trigram " << input[i] << input[i+1] << input[i+2] << endl; count += 1; // self if (i > lastTrigram) { // prefixes count += (i - lastTrigram) + (i - lastTrigram) * (input.length() - i - 3); } count += input.length() - i - 3; // postfixes // cout << "count after: " << count << endl; lastTrigram = i+1; } } cout << count << endl; return 0; } |