#include <bits/stdc++.h> using namespace std; string s = "aeyuio"; char M['z' + 1]; vector<int> D; int main() { for (int i = 'a'; i <= 'z'; ++i) { M[i] = 'b'; } for (auto c: s) { M[(int)c] = 'a'; } cin >> s; for (auto &c: s) { c = M[(int)c]; } int d = 1; for (int i = 1; i < (int)s.size(); ++i) { if (s[i - 1] == s[i]) { ++d; } else { D.push_back(d); d = 1; } } D.push_back(d); long long a = s.size(); a = a * (a + 1) / 2; long long b = s.size() + s.size() - 1; d = 0; for (int i = 0; i < (int)D.size(); ++i) { if (D[i] < 3) { d += D[i]; } else { d += 2; if (d >= 3) { b += (long long)(d - 2) * (d - 1) / 2; } d = 2; } } if (d >= 3) { b += (long long)(d - 2) * (d - 1) / 2; } cout << a - b << 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 50 | #include <bits/stdc++.h> using namespace std; string s = "aeyuio"; char M['z' + 1]; vector<int> D; int main() { for (int i = 'a'; i <= 'z'; ++i) { M[i] = 'b'; } for (auto c: s) { M[(int)c] = 'a'; } cin >> s; for (auto &c: s) { c = M[(int)c]; } int d = 1; for (int i = 1; i < (int)s.size(); ++i) { if (s[i - 1] == s[i]) { ++d; } else { D.push_back(d); d = 1; } } D.push_back(d); long long a = s.size(); a = a * (a + 1) / 2; long long b = s.size() + s.size() - 1; d = 0; for (int i = 0; i < (int)D.size(); ++i) { if (D[i] < 3) { d += D[i]; } else { d += 2; if (d >= 3) { b += (long long)(d - 2) * (d - 1) / 2; } d = 2; } } if (d >= 3) { b += (long long)(d - 2) * (d - 1) / 2; } cout << a - b << endl; return 0; } |