#include<iostream>
#include<string>
using namespace std;
string s;
bool isVowel(char a){
switch(a){
case 'a': return true;
case 'e': return true;
case 'i': return true;
case 'o': return true;
case 'u': return true;
case 'y': return true;
default: return false;
}
}
long long int hardSubwordsCount = 0;
long long int lastHardIdx = 0;
bool vowelity[3];
bool hardSuffix(){
if (vowelity[0] && vowelity[1] && vowelity[2]) return true;
if (!vowelity[0] && !vowelity[1] && !vowelity[2]) return true;
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin >> s;
if(s.length() < 3){
cout << 0 << endl;
return 0;
}
vowelity[1] = isVowel(s[0]);
vowelity[2] = isVowel(s[1]);
for (unsigned int i = 0; i < s.length() - 2; ++i){
vowelity[0] = vowelity[1];
vowelity[1] = vowelity[2];
vowelity[2] = isVowel(s[i + 2]);
if (hardSuffix()) {
lastHardIdx = i + 1;
}
hardSubwordsCount += lastHardIdx;
}
cout << hardSubwordsCount << endl;
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 | #include<iostream> #include<string> using namespace std; string s; bool isVowel(char a){ switch(a){ case 'a': return true; case 'e': return true; case 'i': return true; case 'o': return true; case 'u': return true; case 'y': return true; default: return false; } } long long int hardSubwordsCount = 0; long long int lastHardIdx = 0; bool vowelity[3]; bool hardSuffix(){ if (vowelity[0] && vowelity[1] && vowelity[2]) return true; if (!vowelity[0] && !vowelity[1] && !vowelity[2]) return true; return false; } int main(){ ios_base::sync_with_stdio(false); cin >> s; if(s.length() < 3){ cout << 0 << endl; return 0; } vowelity[1] = isVowel(s[0]); vowelity[2] = isVowel(s[1]); for (unsigned int i = 0; i < s.length() - 2; ++i){ vowelity[0] = vowelity[1]; vowelity[1] = vowelity[2]; vowelity[2] = isVowel(s[i + 2]); if (hardSuffix()) { lastHardIdx = i + 1; } hardSubwordsCount += lastHardIdx; } cout << hardSubwordsCount << endl; return 0; } |
English