#include <bits/stdc++.h> using namespace std; bool letter[27] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}; bool tab[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; cin >> a; for(int i = 0; i < a.size(); i++){ int x = a[i] - 'a'; tab[i + 1] = letter[x]; } int cnts = 0; int cntx = 0; long long cnt = 0; int last = 0; for(int i = 1; i <= a.size(); i++){ if(tab[i] == true){ cnts++; cntx = 0; } else{ cnts = 0; cntx++; } if(cntx >= 3 || cnts >= 3){ cnt += (long long)(i - 2 - last)*(a.size() - i + 1); last = i - 2; } } cout << cnt << '\n'; 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 | #include <bits/stdc++.h> using namespace std; bool letter[27] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}; bool tab[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; cin >> a; for(int i = 0; i < a.size(); i++){ int x = a[i] - 'a'; tab[i + 1] = letter[x]; } int cnts = 0; int cntx = 0; long long cnt = 0; int last = 0; for(int i = 1; i <= a.size(); i++){ if(tab[i] == true){ cnts++; cntx = 0; } else{ cnts = 0; cntx++; } if(cntx >= 3 || cnts >= 3){ cnt += (long long)(i - 2 - last)*(a.size() - i + 1); last = i - 2; } } cout << cnt << '\n'; return 0; } |