#include <iostream> /* Autor: Helena Borak-Wejster */ using namespace std; bool is_vowel(char a){ if(a=='a'||a=='o'||a=='u'||a=='e'||a=='y'||a=='i') return true; return false; } bool is_hard_part(char a1, char a2, char a3) { bool b1 = is_vowel(a1); bool b2 = is_vowel(a2); bool b3 = is_vowel(a3); if(b1 && b2 && b3) return true; if(!b1 && !b2 && !b3) return true; return false; } long long int scan(string input) { long long int sizes = input.size(); long long int sum = 0; bool was_match = false; long long int last_match = 0; for(long long int i=0;i<(sizes-2); i++) { if(is_hard_part(input[i], input[i+1], input[i+2])){ if(!was_match) sum += (i+1)*(sizes-(i+2))-1; else { long long int diff = i-last_match; sum += (diff>0?diff:1)*(sizes-(i+2)); } last_match = i; was_match=true; //cout << sum << endl; } } if(!was_match) return 0; return sum+1; } int main() { string input; cin >> input; cout << scan(input) << 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 | #include <iostream> /* Autor: Helena Borak-Wejster */ using namespace std; bool is_vowel(char a){ if(a=='a'||a=='o'||a=='u'||a=='e'||a=='y'||a=='i') return true; return false; } bool is_hard_part(char a1, char a2, char a3) { bool b1 = is_vowel(a1); bool b2 = is_vowel(a2); bool b3 = is_vowel(a3); if(b1 && b2 && b3) return true; if(!b1 && !b2 && !b3) return true; return false; } long long int scan(string input) { long long int sizes = input.size(); long long int sum = 0; bool was_match = false; long long int last_match = 0; for(long long int i=0;i<(sizes-2); i++) { if(is_hard_part(input[i], input[i+1], input[i+2])){ if(!was_match) sum += (i+1)*(sizes-(i+2))-1; else { long long int diff = i-last_match; sum += (diff>0?diff:1)*(sizes-(i+2)); } last_match = i; was_match=true; //cout << sum << endl; } } if(!was_match) return 0; return sum+1; } int main() { string input; cin >> input; cout << scan(input) << endl; return 0; } |