#include<bits/stdc++.h> using namespace std; using LLong = long long int; void transformInput(string &input, vector<bool> &type); LLong solution(vector<bool> &input){ vector<int> position; for(int i = 0; i<(int)input.size()-2; i++) if(input[i] == input[i+1] && input[i+1] == input[i+2]) position.push_back(i); if(position.size() == 0) return 0; LLong result=0; int i = 0; for(int k = 0; k<(int)position.size(); k++) while(i<=position[k]){ result+=(input.size()-position[k]-2); i++; } return result; } long long int solve(string &input){ vector<bool> type; transformInput(input,type); return solution(type); } int main(){ ios_base::sync_with_stdio(0); string input; cin>>input; cout<<solve(input)<<endl; } void transformInput(string &input, vector<bool> &type){ vector<char> samogloski = {'a','e','i','o','u','y'}; type.clear(); type.shrink_to_fit(); type.resize(input.size(),false); for(unsigned int i = 0;i<input.size(); i++) type[i] = (find(samogloski.begin(), samogloski.end(),input[i]) != samogloski.end()); }
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 | #include<bits/stdc++.h> using namespace std; using LLong = long long int; void transformInput(string &input, vector<bool> &type); LLong solution(vector<bool> &input){ vector<int> position; for(int i = 0; i<(int)input.size()-2; i++) if(input[i] == input[i+1] && input[i+1] == input[i+2]) position.push_back(i); if(position.size() == 0) return 0; LLong result=0; int i = 0; for(int k = 0; k<(int)position.size(); k++) while(i<=position[k]){ result+=(input.size()-position[k]-2); i++; } return result; } long long int solve(string &input){ vector<bool> type; transformInput(input,type); return solution(type); } int main(){ ios_base::sync_with_stdio(0); string input; cin>>input; cout<<solve(input)<<endl; } void transformInput(string &input, vector<bool> &type){ vector<char> samogloski = {'a','e','i','o','u','y'}; type.clear(); type.shrink_to_fit(); type.resize(input.size(),false); for(unsigned int i = 0;i<input.size(); i++) type[i] = (find(samogloski.begin(), samogloski.end(),input[i]) != samogloski.end()); } |