#include <iostream> using namespace std; typedef long long LL; bool IsVovel(char x) { return (x == 'a') || (x == 'e') || (x == 'i') || (x == 'o') || (x == 'u') || (x == 'y'); } int main() { string s; cin >> s; int n = s.length(); LL result = 0; int last = 0; bool vovel = true; int cnt = 0; for (int i=0; i<n+1; ++i) { if (i < n) { if (IsVovel(s[i]) == vovel) { ++cnt; } else { vovel = !vovel; cnt = 1; } } if (cnt >= 3 || i == n) { // printf("%d - %d\n", last, i); result += (LL)(i - last) * (i - last - 1) / 2; last = i-1; } } result += n; result = (LL)n * (n+1) / 2 - result; printf("%lld\n", result); 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 | #include <iostream> using namespace std; typedef long long LL; bool IsVovel(char x) { return (x == 'a') || (x == 'e') || (x == 'i') || (x == 'o') || (x == 'u') || (x == 'y'); } int main() { string s; cin >> s; int n = s.length(); LL result = 0; int last = 0; bool vovel = true; int cnt = 0; for (int i=0; i<n+1; ++i) { if (i < n) { if (IsVovel(s[i]) == vovel) { ++cnt; } else { vovel = !vovel; cnt = 1; } } if (cnt >= 3 || i == n) { // printf("%d - %d\n", last, i); result += (LL)(i - last) * (i - last - 1) / 2; last = i-1; } } result += n; result = (LL)n * (n+1) / 2 - result; printf("%lld\n", result); return 0; } |