#include <string>
#include <iostream>
#include <set>
using namespace std;
string str;
char v[] = {'a', 'e', 'i', 'o', 'u', 'y'};
set<char> vowels(v, v + 6);
bool triple(char c1, char c2, char c3) {
auto it1 = vowels.find(c1);
auto it2 = vowels.find(c2);
auto it3 = vowels.find(c3);
return (it1 == vowels.end() && it2 == vowels.end() && it3 == vowels.end())
|| (it1 != vowels.end() && it2 != vowels.end() && it3 != vowels.end());
}
int main() {
cin >> str;
long long result = 0LL;
long long part = 0LL;
int last_triple_index = -1;
for (int i = 2; i < str.length(); i++) {
if (triple(str[i - 2], str[i - 1], str[i])) {
part += i - last_triple_index - 2;
last_triple_index = i - 2;
}
result += part;
}
cout << result << 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 | #include <string> #include <iostream> #include <set> using namespace std; string str; char v[] = {'a', 'e', 'i', 'o', 'u', 'y'}; set<char> vowels(v, v + 6); bool triple(char c1, char c2, char c3) { auto it1 = vowels.find(c1); auto it2 = vowels.find(c2); auto it3 = vowels.find(c3); return (it1 == vowels.end() && it2 == vowels.end() && it3 == vowels.end()) || (it1 != vowels.end() && it2 != vowels.end() && it3 != vowels.end()); } int main() { cin >> str; long long result = 0LL; long long part = 0LL; int last_triple_index = -1; for (int i = 2; i < str.length(); i++) { if (triple(str[i - 2], str[i - 1], str[i])) { part += i - last_triple_index - 2; last_triple_index = i - 2; } result += part; } cout << result << endl; return 0; } |
English