#include <iostream> #include <string> using namespace std; unsigned long long count = 0; string text; unsigned long long lastFound = 1; bool isVowel(char c) { switch(c) { 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; } } void foundExactTriplet(unsigned long long idx) { unsigned long long before = idx - lastFound - 1; unsigned long long after = text.size() - idx - 1; unsigned long long helpCount = (before + 1) * (after + 1); count += helpCount; } int main() { cin >> text; unsigned long long consVowels = 0; unsigned long long consConsonants = 0; char prev; for (unsigned long long i = 0; i < text.size(); i++) { if (isVowel(text[i])) { consConsonants = 0; if (i != 0 && isVowel(prev)) { consVowels++; if (consVowels >= 3) { foundExactTriplet(i); lastFound = i; } } else { consVowels = 1; } } else { //is consonant consVowels = 0; if (!isVowel(text[i])) { if (i !=0 && !isVowel(prev)) { consConsonants++; if (consConsonants >= 3) { foundExactTriplet(i); lastFound = i; } } else { consConsonants = 1; } } } prev = text[i]; } cout << count << 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <iostream> #include <string> using namespace std; unsigned long long count = 0; string text; unsigned long long lastFound = 1; bool isVowel(char c) { switch(c) { 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; } } void foundExactTriplet(unsigned long long idx) { unsigned long long before = idx - lastFound - 1; unsigned long long after = text.size() - idx - 1; unsigned long long helpCount = (before + 1) * (after + 1); count += helpCount; } int main() { cin >> text; unsigned long long consVowels = 0; unsigned long long consConsonants = 0; char prev; for (unsigned long long i = 0; i < text.size(); i++) { if (isVowel(text[i])) { consConsonants = 0; if (i != 0 && isVowel(prev)) { consVowels++; if (consVowels >= 3) { foundExactTriplet(i); lastFound = i; } } else { consVowels = 1; } } else { //is consonant consVowels = 0; if (!isVowel(text[i])) { if (i !=0 && !isVowel(prev)) { consConsonants++; if (consConsonants >= 3) { foundExactTriplet(i); lastFound = i; } } else { consConsonants = 1; } } } prev = text[i]; } cout << count << endl; } |