#include<stdlib.h> #include<iostream> #include<string> using namespace std; long N; long sum = 0; string parse () { string line; cin >> line; return line; } int isSam (char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int main () { string line = parse(); int p1 = -1, p2 = -1; long int len = line.length(); int is_sam = -2; long int last_g = -1; long int l1, l2; for (int i = 0; i < len; ++i) { is_sam = isSam(line[i]); if (is_sam == p1 && is_sam == p2) { l1 = i - last_g - 3; l1 = l1 >= 0 ? l1 + 1 : 1; l2 = len - i; sum += l1 * l2; // cout << "trojka\n" << len << l1 << l2 << last_g << i << endl; last_g = i; } p2 = p1; p1 = is_sam; } // cout << 1 << line[0] << line[1] << endl; cout << sum << 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 | #include<stdlib.h> #include<iostream> #include<string> using namespace std; long N; long sum = 0; string parse () { string line; cin >> line; return line; } int isSam (char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } int main () { string line = parse(); int p1 = -1, p2 = -1; long int len = line.length(); int is_sam = -2; long int last_g = -1; long int l1, l2; for (int i = 0; i < len; ++i) { is_sam = isSam(line[i]); if (is_sam == p1 && is_sam == p2) { l1 = i - last_g - 3; l1 = l1 >= 0 ? l1 + 1 : 1; l2 = len - i; sum += l1 * l2; // cout << "trojka\n" << len << l1 << l2 << last_g << i << endl; last_g = i; } p2 = p1; p1 = is_sam; } // cout << 1 << line[0] << line[1] << endl; cout << sum << endl; return 0; } |