#include <bits/stdc++.h> using namespace std; bool samogloski[300]; void prepare(){ samogloski['a'] = 1; samogloski['e'] = 1; samogloski['i'] = 1; samogloski['o'] = 1; samogloski['u'] = 1; samogloski['y'] = 1; } bool has_three(string& s, int index){ if((samogloski[(int)s[index]] && samogloski[(int)s[index + 1]]) && samogloski[(int)s[index + 2]]){ return true; } if((!samogloski[(int)s[index]] && !samogloski[(int)s[index + 1]]) && !samogloski[(int)s[index + 2]]){ return true; } return false; } int main(){ prepare(); string s; cin>>s; long long size = s.size(); long long result = 0; long long last = 0; for(long long i = 0; i + 2 <= size-1; i++){ if(has_three(s, i)){ result += (i - last + 1) * (size - i - 2); last = i + 1; } } cout<<result<<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 | #include <bits/stdc++.h> using namespace std; bool samogloski[300]; void prepare(){ samogloski['a'] = 1; samogloski['e'] = 1; samogloski['i'] = 1; samogloski['o'] = 1; samogloski['u'] = 1; samogloski['y'] = 1; } bool has_three(string& s, int index){ if((samogloski[(int)s[index]] && samogloski[(int)s[index + 1]]) && samogloski[(int)s[index + 2]]){ return true; } if((!samogloski[(int)s[index]] && !samogloski[(int)s[index + 1]]) && !samogloski[(int)s[index + 2]]){ return true; } return false; } int main(){ prepare(); string s; cin>>s; long long size = s.size(); long long result = 0; long long last = 0; for(long long i = 0; i + 2 <= size-1; i++){ if(has_three(s, i)){ result += (i - last + 1) * (size - i - 2); last = i + 1; } } cout<<result<<endl; } |