#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) #define FORR(i, n) for (int i = 1; i <= n; i++) #define FORi(n) for (int i = 0; i < n; i++) long long dp[200100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; // cout << s << "\n"; int n = s.size(); int l1 = 0, l2 = 0; for (int i = 0; i < n; i++) { // cout << s[i] << "\n"; if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') { s[i] = 'a'; // l1++; } else { s[i] = 'b'; // l2++; } } // cout << l1 << " " << l2 << " " << n << "\n"; // cout << s << "\n"; int l = 0; for (int i = 0; i < n; i++) { if (i != 0) dp[i] = dp[i - 1]; if (i > 1) { if (s[i] == s[i - 1] && s[i - 2] == s[i - 1]) { l = i - 1; } } dp[i] += l; } // for (int i = 0; i < n; i++) // cout << dp[i] << " "; cout << dp[n - 1]; 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 | #include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) #define FORR(i, n) for (int i = 1; i <= n; i++) #define FORi(n) for (int i = 0; i < n; i++) long long dp[200100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; // cout << s << "\n"; int n = s.size(); int l1 = 0, l2 = 0; for (int i = 0; i < n; i++) { // cout << s[i] << "\n"; if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') { s[i] = 'a'; // l1++; } else { s[i] = 'b'; // l2++; } } // cout << l1 << " " << l2 << " " << n << "\n"; // cout << s << "\n"; int l = 0; for (int i = 0; i < n; i++) { if (i != 0) dp[i] = dp[i - 1]; if (i > 1) { if (s[i] == s[i - 1] && s[i - 2] == s[i - 1]) { l = i - 1; } } dp[i] += l; } // for (int i = 0; i < n; i++) // cout << dp[i] << " "; cout << dp[n - 1]; return 0; } |