#include <iostream> #include <string> using namespace std; string s; bool isVowel(char c) { return (c == 'a' || c == 'e' || c =='i' || c == 'o' || c == 'u' || c == 'y'); } bool isHard(char a, char b, char c) { return ((isVowel(a) && isVowel(b) && isVowel(c)) || (!isVowel(a) && !isVowel(b) && !isVowel(c))); } long long cutToFirstHard() { long long i = 0; long long n = s.length(); while (i < n - 2 && !isHard(s[i], s[i+1], s[i+2])) i++; if (i >= n - 2) { s = ""; return 0; } s.erase (0, i+1); return (i + 1) * (n - (i+2)); } int main() { long long ret = 0; cin >> s; while(s.length() > 0) ret += cutToFirstHard(); cout << ret << 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 | #include <iostream> #include <string> using namespace std; string s; bool isVowel(char c) { return (c == 'a' || c == 'e' || c =='i' || c == 'o' || c == 'u' || c == 'y'); } bool isHard(char a, char b, char c) { return ((isVowel(a) && isVowel(b) && isVowel(c)) || (!isVowel(a) && !isVowel(b) && !isVowel(c))); } long long cutToFirstHard() { long long i = 0; long long n = s.length(); while (i < n - 2 && !isHard(s[i], s[i+1], s[i+2])) i++; if (i >= n - 2) { s = ""; return 0; } s.erase (0, i+1); return (i + 1) * (n - (i+2)); } int main() { long long ret = 0; cin >> s; while(s.length() > 0) ret += cutToFirstHard(); cout << ret << endl; return 0; } |