#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); unordered_map<char, bool> letters; const int SPOL = 0, SAMO = 1; for(int i=0; i<26; i++) { letters['a' + 1] = SPOL; } letters['a'] = SAMO; letters['e'] = SAMO; letters['i'] = SAMO; letters['o'] = SAMO; letters['u'] = SAMO; letters['y'] = SAMO; string s; cin >> s; long long result = 0; int cnt[2] = {0, 0}; int siz = s.size(), lastTraf = -1; char prev = '/'; for(int i=0; i<siz; i++) { int let = letters[s[i]]; if(letters[prev] == let) { cnt[let]++; if(cnt[let] == 3) { if(lastTraf == -1) { result += (i - 2) + 1; } else { result += (i - 2) + 1; int a = lastTraf - 2, b = i - lastTraf - 1; result += (b + a*b); } lastTraf = i; } else if(cnt[let] > 3) { result += (i - 2 + 1); lastTraf = i; } } else { cnt[let]++; cnt[1 - let] = 0; } prev = s[i]; } if(lastTraf != -1) { int b = siz - 1 - lastTraf; int a = lastTraf - 2; result += (b + a*b); } cout << result << 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 48 49 | #include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); unordered_map<char, bool> letters; const int SPOL = 0, SAMO = 1; for(int i=0; i<26; i++) { letters['a' + 1] = SPOL; } letters['a'] = SAMO; letters['e'] = SAMO; letters['i'] = SAMO; letters['o'] = SAMO; letters['u'] = SAMO; letters['y'] = SAMO; string s; cin >> s; long long result = 0; int cnt[2] = {0, 0}; int siz = s.size(), lastTraf = -1; char prev = '/'; for(int i=0; i<siz; i++) { int let = letters[s[i]]; if(letters[prev] == let) { cnt[let]++; if(cnt[let] == 3) { if(lastTraf == -1) { result += (i - 2) + 1; } else { result += (i - 2) + 1; int a = lastTraf - 2, b = i - lastTraf - 1; result += (b + a*b); } lastTraf = i; } else if(cnt[let] > 3) { result += (i - 2 + 1); lastTraf = i; } } else { cnt[let]++; cnt[1 - let] = 0; } prev = s[i]; } if(lastTraf != -1) { int b = siz - 1 - lastTraf; int a = lastTraf - 2; result += (b + a*b); } cout << result << endl; return 0; } |