#include <vector> #include <iostream> #include <algorithm> using namespace std; const vector<char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; bool difficult_word( const vector<char>::iterator& first, const vector<char>::iterator last ) { bool all_vowels = all_of( first, last, []( char c ) { return find( vowels.begin(), vowels.end(), c ) != vowels.end(); } ); bool all_consonant = none_of( first, last, []( char c ) { return find( vowels.begin(), vowels.end(), c ) != vowels.end(); } ); return all_vowels || all_consonant; } int main() { vector<char> text; text.reserve( 200001 ); while ( cin.good() ) { char c; cin >> c; text.push_back( c ); } if ( text.size() < 4U ) { cout << "0" << endl; return 0; } uint32_t n = 0U; uint32_t m = 0U; for ( size_t i = 0; i < text.size() - 3; i++ ) { auto first = text.begin() + i; auto last = first + 3; if ( difficult_word( first, last ) ) { n += text.size() - 1U - 2U + i * ( text.size() - 1U - i - 3U ); m++; } } n -= ( m - 1 ); cout << 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 | #include <vector> #include <iostream> #include <algorithm> using namespace std; const vector<char> vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; bool difficult_word( const vector<char>::iterator& first, const vector<char>::iterator last ) { bool all_vowels = all_of( first, last, []( char c ) { return find( vowels.begin(), vowels.end(), c ) != vowels.end(); } ); bool all_consonant = none_of( first, last, []( char c ) { return find( vowels.begin(), vowels.end(), c ) != vowels.end(); } ); return all_vowels || all_consonant; } int main() { vector<char> text; text.reserve( 200001 ); while ( cin.good() ) { char c; cin >> c; text.push_back( c ); } if ( text.size() < 4U ) { cout << "0" << endl; return 0; } uint32_t n = 0U; uint32_t m = 0U; for ( size_t i = 0; i < text.size() - 3; i++ ) { auto first = text.begin() + i; auto last = first + 3; if ( difficult_word( first, last ) ) { n += text.size() - 1U - 2U + i * ( text.size() - 1U - i - 3U ); m++; } } n -= ( m - 1 ); cout << n; return 0; } |