#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; static long long _count = 0; string _hash = ""; // To store vowels bool isVowel(char ch) { return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'); } bool isConsonant(char ch) { return !(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'); } void findTriplets(string str) { long long n = str.length(); int vowel = 0; _hash = ""; long long index = 0; for (long long i = 0; i < n; i++) { if (isVowel(str[i])) { if(i>0) if(vowel != 1) _hash = ""; vowel = 1; if(_hash.length() == 3) { _hash[0] = _hash[1]; _hash[1] = _hash[2]; _hash = _hash.substr(0,2); } _hash = _hash + str[i]; if(_hash.length() == 3) { index = i; _count = _count + (i-1); continue; } } if(isConsonant(str[i])) { if(i>0) if(vowel != 0) _hash = ""; vowel = 0; if(_hash.length() == 3) { _hash[0] = _hash[1]; _hash[1] = _hash[2]; _hash = _hash.substr(0,2); } _hash = _hash + str[i]; if(_hash.length() == 3) { index = i; _count = _count + (i-1); continue; } } if( index != 0 ) _count = _count+(index-1); } } int main() { std::string data; std::cin>>data; findTriplets(data); cout<<_count<<endl; cin>>_count; 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; static long long _count = 0; string _hash = ""; // To store vowels bool isVowel(char ch) { return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'); } bool isConsonant(char ch) { return !(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'); } void findTriplets(string str) { long long n = str.length(); int vowel = 0; _hash = ""; long long index = 0; for (long long i = 0; i < n; i++) { if (isVowel(str[i])) { if(i>0) if(vowel != 1) _hash = ""; vowel = 1; if(_hash.length() == 3) { _hash[0] = _hash[1]; _hash[1] = _hash[2]; _hash = _hash.substr(0,2); } _hash = _hash + str[i]; if(_hash.length() == 3) { index = i; _count = _count + (i-1); continue; } } if(isConsonant(str[i])) { if(i>0) if(vowel != 0) _hash = ""; vowel = 0; if(_hash.length() == 3) { _hash[0] = _hash[1]; _hash[1] = _hash[2]; _hash = _hash.substr(0,2); } _hash = _hash + str[i]; if(_hash.length() == 3) { index = i; _count = _count + (i-1); continue; } } if( index != 0 ) _count = _count+(index-1); } } int main() { std::string data; std::cin>>data; findTriplets(data); cout<<_count<<endl; cin>>_count; return 0; } |