#include <iostream> #include <vector> #include <utility> #include <string> bool IsVowel(char c) { return (c == 'a')||(c == 'e')||(c == 'i')||(c == 'o')||(c == 'u')||(c == 'y'); } bool IsConsonant(char c) { return not IsVowel(c); } int main() { std::ios_base::sync_with_stdio(false); std::string s; std::cin >> s; std::vector< std::pair<int, int> > blocks; int vowels = 0; int consonants = 0; for (int i = 0; i < s.length(); i++) { if (IsVowel(s[i])) { if (consonants >= 3) { blocks.push_back(std::make_pair(i - consonants, i - 1)); } vowels++; consonants = 0; } else { if (vowels >= 3) { blocks.push_back(std::make_pair(i - vowels, i - 1)); } vowels = 0; consonants++; } } if (consonants >= 3) { blocks.push_back(std::make_pair(s.length() - consonants, s.length() - 1)); } if (vowels >= 3) { blocks.push_back(std::make_pair(s.length() - vowels, s.length() - 1)); } if (blocks.size() == 0) { std::cout << "0\n"; return 0; } long long result = 0; int block_idx = 0; for (int i = 0; i < s.length(); i++) { if (blocks[block_idx].second - i < 2) { ++block_idx; } if (block_idx == blocks.size()) { break; } result += (s.length() - std::max(blocks[block_idx].first + 2, i + 2)); } std::cout << result << '\n'; 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 | #include <iostream> #include <vector> #include <utility> #include <string> bool IsVowel(char c) { return (c == 'a')||(c == 'e')||(c == 'i')||(c == 'o')||(c == 'u')||(c == 'y'); } bool IsConsonant(char c) { return not IsVowel(c); } int main() { std::ios_base::sync_with_stdio(false); std::string s; std::cin >> s; std::vector< std::pair<int, int> > blocks; int vowels = 0; int consonants = 0; for (int i = 0; i < s.length(); i++) { if (IsVowel(s[i])) { if (consonants >= 3) { blocks.push_back(std::make_pair(i - consonants, i - 1)); } vowels++; consonants = 0; } else { if (vowels >= 3) { blocks.push_back(std::make_pair(i - vowels, i - 1)); } vowels = 0; consonants++; } } if (consonants >= 3) { blocks.push_back(std::make_pair(s.length() - consonants, s.length() - 1)); } if (vowels >= 3) { blocks.push_back(std::make_pair(s.length() - vowels, s.length() - 1)); } if (blocks.size() == 0) { std::cout << "0\n"; return 0; } long long result = 0; int block_idx = 0; for (int i = 0; i < s.length(); i++) { if (blocks[block_idx].second - i < 2) { ++block_idx; } if (block_idx == blocks.size()) { break; } result += (s.length() - std::max(blocks[block_idx].first + 2, i + 2)); } std::cout << result << '\n'; return 0; } |