#include <iostream> #include <unordered_map> using namespace std; #define int long long main(){ string input; cin>>input; const int size= input.size(); unordered_map <char, int> vowels ={{'a', 1}, {'e', 1}, {'i', 1}, {'o', 1}, {'u',1}, {'y', 1}}; //„a”, „e”, „i”, „o”, „u” oraz „y int all = ((size)*(size+1))/2; int good=0, good_len=2, bad=0; int v=0, c=0, res=0; //string tmp= input.subbstr(0, 2); if (size==1) good=1; if (size==2) good=3; for(int i=2; i<size; i++){ //cout<<input[i]<<endl; if(vowels.find(input[i]) != vowels.end()){ if(vowels.find(input[i-2]) != vowels.end() && vowels.find(input[i-1]) != vowels.end() ){ //cout<<"1 "<<good_len<<endl; good += (good_len+1)*(good_len)/2; good_len=2; bad++; } else{ good_len ++; //cout<<"2 "<<good_len<<endl; //tmp += input; } } else if(vowels.find(input[i]) == vowels.end()){ if(vowels.find(input[i-2]) == vowels.end() && vowels.find(input[i-1]) == vowels.end() ){ //cout<<"3 "<<good_len<<endl; good += (good_len+1)*(good_len)/2; //cout<<"good: :"<<good<<endl; good_len=2; bad++; } else{ good_len ++; //cout<<"4 "<<good_len<<endl; } } } //cout<<"len: "<<good_len<<endl; if(good_len>0) good += (good_len+1)*(good_len)/2; cout<<all-good+bad<<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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <unordered_map> using namespace std; #define int long long main(){ string input; cin>>input; const int size= input.size(); unordered_map <char, int> vowels ={{'a', 1}, {'e', 1}, {'i', 1}, {'o', 1}, {'u',1}, {'y', 1}}; //„a”, „e”, „i”, „o”, „u” oraz „y int all = ((size)*(size+1))/2; int good=0, good_len=2, bad=0; int v=0, c=0, res=0; //string tmp= input.subbstr(0, 2); if (size==1) good=1; if (size==2) good=3; for(int i=2; i<size; i++){ //cout<<input[i]<<endl; if(vowels.find(input[i]) != vowels.end()){ if(vowels.find(input[i-2]) != vowels.end() && vowels.find(input[i-1]) != vowels.end() ){ //cout<<"1 "<<good_len<<endl; good += (good_len+1)*(good_len)/2; good_len=2; bad++; } else{ good_len ++; //cout<<"2 "<<good_len<<endl; //tmp += input; } } else if(vowels.find(input[i]) == vowels.end()){ if(vowels.find(input[i-2]) == vowels.end() && vowels.find(input[i-1]) == vowels.end() ){ //cout<<"3 "<<good_len<<endl; good += (good_len+1)*(good_len)/2; //cout<<"good: :"<<good<<endl; good_len=2; bad++; } else{ good_len ++; //cout<<"4 "<<good_len<<endl; } } } //cout<<"len: "<<good_len<<endl; if(good_len>0) good += (good_len+1)*(good_len)/2; cout<<all-good+bad<<endl; } |