#include <iostream> using namespace std; bool is_v(char letter){ return (letter=='e' || letter=='y' || letter=='u' || letter=='i' || letter=='o' || letter=='a') ? 1 : 0; } int main(){ ios_base::sync_with_stdio(0); string word; cin>>word; int n = word.length(), sum=0, last_triple=-1; for(int i=2; i<n; i++){ if((is_v(word[i-2]) && is_v(word[i-1]) && is_v(word[i])) || (!is_v(word[i-2]) && !is_v(word[i-1]) && !is_v(word[i]))){ if(last_triple>=i-2) sum+=(i-1-(last_triple-1))*(n-i); else sum+=(i-1-(last_triple+1))*(n-i); last_triple=i; } } cout<<sum; 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 | #include <iostream> using namespace std; bool is_v(char letter){ return (letter=='e' || letter=='y' || letter=='u' || letter=='i' || letter=='o' || letter=='a') ? 1 : 0; } int main(){ ios_base::sync_with_stdio(0); string word; cin>>word; int n = word.length(), sum=0, last_triple=-1; for(int i=2; i<n; i++){ if((is_v(word[i-2]) && is_v(word[i-1]) && is_v(word[i])) || (!is_v(word[i-2]) && !is_v(word[i-1]) && !is_v(word[i]))){ if(last_triple>=i-2) sum+=(i-1-(last_triple-1))*(n-i); else sum+=(i-1-(last_triple+1))*(n-i); last_triple=i; } } cout<<sum; return 0; } |