#include <iostream> using namespace std; bool is_vowel(char c) { return c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'; } bool test(const string &s, int a, int b) { if (b-a<2) return false; for (int j=a+2;j<=b;j++) { if (is_vowel(s[j]) == is_vowel(s[j-1]) && is_vowel(s[j]) == is_vowel(s[j-2])) return true; } return false; } int brut(const string &s) { int a=0; for (int i=0;i<s.length();i++) for (int j=i;j<s.length();j++) if (test(s,i,j)) a++; return a; } int main() { //for (char c='a';c<='z';c++) cout << c <<is_vowel(c)<<endl; string s; cin >> s; //cout << brut(s) << endl; long long d = s.length(); if (d<3) { cout << 0; return 0; } int b = 1; long long answer = 0; int i=0; for (int j=1;j<d;j++) { if (is_vowel(s[j]) == is_vowel(s[j-1])) b++; else { b=1; } //cout << s[j]<<is_vowel(s[j])<<" j="<<j<<" b="<<b<<endl; if (b==3) { long long l = j-i-2; if (l>0){ answer += l*(l+1)/2; //cout << "i="<<i<<" j="<<j<<" "<<l*(l+1)/2<<endl; } i=j-1; b--; } } long long l = d-i-2; if (l>0) { answer += l*(l+1)/2; //cout << "i="<<i<<" j="<<d<<" "<<l*(l+1)/2<<endl; } cout << (d-2)*(d-1)/2-answer<<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 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <iostream> using namespace std; bool is_vowel(char c) { return c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'; } bool test(const string &s, int a, int b) { if (b-a<2) return false; for (int j=a+2;j<=b;j++) { if (is_vowel(s[j]) == is_vowel(s[j-1]) && is_vowel(s[j]) == is_vowel(s[j-2])) return true; } return false; } int brut(const string &s) { int a=0; for (int i=0;i<s.length();i++) for (int j=i;j<s.length();j++) if (test(s,i,j)) a++; return a; } int main() { //for (char c='a';c<='z';c++) cout << c <<is_vowel(c)<<endl; string s; cin >> s; //cout << brut(s) << endl; long long d = s.length(); if (d<3) { cout << 0; return 0; } int b = 1; long long answer = 0; int i=0; for (int j=1;j<d;j++) { if (is_vowel(s[j]) == is_vowel(s[j-1])) b++; else { b=1; } //cout << s[j]<<is_vowel(s[j])<<" j="<<j<<" b="<<b<<endl; if (b==3) { long long l = j-i-2; if (l>0){ answer += l*(l+1)/2; //cout << "i="<<i<<" j="<<j<<" "<<l*(l+1)/2<<endl; } i=j-1; b--; } } long long l = d-i-2; if (l>0) { answer += l*(l+1)/2; //cout << "i="<<i<<" j="<<d<<" "<<l*(l+1)/2<<endl; } cout << (d-2)*(d-1)/2-answer<<endl; return 0; } |