#include <iostream> #include <set> using namespace std; int main() { const set<char> VOVELS = {'a','e','i','o','u','y'}; int lastStartOfCluster = 0; int inRow = 1; bool lastWasVovel = true; long long difficults = 0; char chr; cin >> chr; if (VOVELS.find(chr) == VOVELS.end()) {// chr is a consonant lastWasVovel = false; } int i = 2; while (cin >> chr) { if (VOVELS.find(chr) == VOVELS.end()) {// chr is a consonant if (lastWasVovel) { lastWasVovel = false; inRow = 1; } else { ++inRow; if (inRow >= 3) { lastStartOfCluster = i - 2; } } } else {// chr is a vovel if (!lastWasVovel) { lastWasVovel = true; inRow = 1; } else { ++inRow; if (inRow >= 3) { lastStartOfCluster = i - 2; } } } difficults += lastStartOfCluster; ++i; } cout << difficults << 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 50 51 52 53 54 55 56 57 58 | #include <iostream> #include <set> using namespace std; int main() { const set<char> VOVELS = {'a','e','i','o','u','y'}; int lastStartOfCluster = 0; int inRow = 1; bool lastWasVovel = true; long long difficults = 0; char chr; cin >> chr; if (VOVELS.find(chr) == VOVELS.end()) {// chr is a consonant lastWasVovel = false; } int i = 2; while (cin >> chr) { if (VOVELS.find(chr) == VOVELS.end()) {// chr is a consonant if (lastWasVovel) { lastWasVovel = false; inRow = 1; } else { ++inRow; if (inRow >= 3) { lastStartOfCluster = i - 2; } } } else {// chr is a vovel if (!lastWasVovel) { lastWasVovel = true; inRow = 1; } else { ++inRow; if (inRow >= 3) { lastStartOfCluster = i - 2; } } } difficults += lastStartOfCluster; ++i; } cout << difficults << endl; return 0; } |