#include <cstdio> #include <iostream> using namespace std; long long substringNum(long long n) { return (n + 1) * n / 2; } int type(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { return 1; } return 2; } bool lastThree(const string& s, int i) { if (i < 2) { return false; } return (type(s[i]) == type(s[i - 1]) && type(s[i]) == type(s[i - 2])); } int main() { ios_base::sync_with_stdio(0); string s; int begin = 0; long long sum = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (lastThree(s, i)) { begin = i - 1; } sum += i - begin + 1; } cout << (substringNum(s.size()) - sum) << endl; }
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 | #include <cstdio> #include <iostream> using namespace std; long long substringNum(long long n) { return (n + 1) * n / 2; } int type(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { return 1; } return 2; } bool lastThree(const string& s, int i) { if (i < 2) { return false; } return (type(s[i]) == type(s[i - 1]) && type(s[i]) == type(s[i - 2])); } int main() { ios_base::sync_with_stdio(0); string s; int begin = 0; long long sum = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (lastThree(s, i)) { begin = i - 1; } sum += i - begin + 1; } cout << (substringNum(s.size()) - sum) << endl; } |