#include <iostream> #include <vector> #include <string> using namespace std; int main() { string text; cin>>text; int length=text.length(); vector<int>number(length); for(int i=0; i<length; i++){ if(text[i]=='a' || text[i]=='e' ||text[i]=='i' ||text[i]=='o' ||text[i]=='u' ||text[i]=='y'){ number[i]=0; } else{ number[i]=1; } } vector<int>triples; if(length>2){ for(int i=0; i<length-2; i++){ if(number[i]==number[i+1] && number[i]==number[i+2]){ triples.push_back(i); } } } if(triples.size()==0){ cout << 0; return 0; } long long sum=0; sum+=(triples[0]+1)*(length-triples[0]-2); for(int i=1; i<triples.size(); i++){ sum+=(triples[i]-triples[i-1])*(length-triples[i]-2); } 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <iostream> #include <vector> #include <string> using namespace std; int main() { string text; cin>>text; int length=text.length(); vector<int>number(length); for(int i=0; i<length; i++){ if(text[i]=='a' || text[i]=='e' ||text[i]=='i' ||text[i]=='o' ||text[i]=='u' ||text[i]=='y'){ number[i]=0; } else{ number[i]=1; } } vector<int>triples; if(length>2){ for(int i=0; i<length-2; i++){ if(number[i]==number[i+1] && number[i]==number[i+2]){ triples.push_back(i); } } } if(triples.size()==0){ cout << 0; return 0; } long long sum=0; sum+=(triples[0]+1)*(length-triples[0]-2); for(int i=1; i<triples.size(); i++){ sum+=(triples[i]-triples[i-1])*(length-triples[i]-2); } cout << sum; return 0; } |