#include <bits/stdc++.h> using namespace std; int znak(char q) { if(q=='a' || q=='e' || q=='i' || q=='o' || q=='u' || q=='y') return 0; return 1; } int main() { string s; cin >> s; s = '.' + s; long long n = s.length() - 1; vector<long long> pocz; vector<long long>kon; long long b = 1; long long e = 1; while(e<n) { while(e < n && znak(s[e]) == znak(s[e+1])) e++; if(e - b >= 2) { pocz.push_back(b); kon.push_back(e); e++; b = e; } else { b++; e = b; } } int w = pocz.size(); long long dobre = 0; for(int i=0;i<w;i++) { long long a = kon[i] - pocz[i] - 2; //long long ? if(a > 0) { dobre += (2 * a - 1); //cout << "tu :" << dobre << "\n"; } } long long przod = 1; long long tyl; long long r; for(int i=0;i<w;i++) { tyl = pocz[i] + 1; r = tyl - przod + 1; dobre += (r * (r + 1)) / 2; przod = kon[i] - 1; } tyl = n; r = tyl - przod + 1; dobre += (r*(r+1))/2; for(int i=0;i<w;i++) if(kon[i] - pocz[i] == 2) dobre--; long long res = (n * (n+1)) / 2 - dobre; cout << res; /* cout << "\n"; cout << dobre << "\n"; for(int i=0;i<pocz.size();i++) cout << pocz[i] << " "; cout << "\n"; for(int i=0;i<kon.size();i++) cout << kon[i] << " "; cout << "\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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #include <bits/stdc++.h> using namespace std; int znak(char q) { if(q=='a' || q=='e' || q=='i' || q=='o' || q=='u' || q=='y') return 0; return 1; } int main() { string s; cin >> s; s = '.' + s; long long n = s.length() - 1; vector<long long> pocz; vector<long long>kon; long long b = 1; long long e = 1; while(e<n) { while(e < n && znak(s[e]) == znak(s[e+1])) e++; if(e - b >= 2) { pocz.push_back(b); kon.push_back(e); e++; b = e; } else { b++; e = b; } } int w = pocz.size(); long long dobre = 0; for(int i=0;i<w;i++) { long long a = kon[i] - pocz[i] - 2; //long long ? if(a > 0) { dobre += (2 * a - 1); //cout << "tu :" << dobre << "\n"; } } long long przod = 1; long long tyl; long long r; for(int i=0;i<w;i++) { tyl = pocz[i] + 1; r = tyl - przod + 1; dobre += (r * (r + 1)) / 2; przod = kon[i] - 1; } tyl = n; r = tyl - przod + 1; dobre += (r*(r+1))/2; for(int i=0;i<w;i++) if(kon[i] - pocz[i] == 2) dobre--; long long res = (n * (n+1)) / 2 - dobre; cout << res; /* cout << "\n"; cout << dobre << "\n"; for(int i=0;i<pocz.size();i++) cout << pocz[i] << " "; cout << "\n"; for(int i=0;i<kon.size();i++) cout << kon[i] << " "; cout << "\n"; */ return 0; } |