# include <cstdio> const int MAX_WORD_SIZE = 300011; const int MAX_ASCII_SIZE = 255; void initialize_vowels( bool vowels[ ] ) { for ( int i = 0; i < MAX_ASCII_SIZE; i ++ ) { vowels[ i ] = 0; } vowels[ 'a' ] = 1; vowels[ 'e' ] = 1; vowels[ 'i' ] = 1; vowels[ 'o' ] = 1; vowels[ 'u' ] = 1; vowels[ 'y' ] = 1; } void solve( char word[ ], bool vowels[ ] ) { int word_length = 0; int vowels_count = 0; int consonants_count = 0; int hard_fragment_positions[ MAX_WORD_SIZE ]; int hard_fragment_positions_size = 0; long long total_hard_fragments = 0; while ( word_length < 2 ) { if ( word[ word_length ] == '\0' ) { printf( "0" ); return; } vowels_count += vowels[ word[ word_length ] ]; consonants_count += 1 - vowels[ word[ word_length ] ]; word_length ++; } while ( word[ word_length ] != '\0' ) { vowels_count += vowels[ word[ word_length ] ]; consonants_count += 1 - vowels[ word[ word_length ] ]; if ( vowels_count == 3 || consonants_count == 3 ) { hard_fragment_positions[ hard_fragment_positions_size ] = word_length; hard_fragment_positions_size ++; } vowels_count -= vowels[ word[ word_length - 2 ] ]; consonants_count -= 1 - vowels[ word[ word_length - 2 ] ]; word_length ++; } hard_fragment_positions[ hard_fragment_positions_size ] = word_length - 1; hard_fragment_positions_size ++; for ( int i = 0; i < hard_fragment_positions_size - 1; i ++ ) { const int pos = hard_fragment_positions[ i ]; const int next_pos = hard_fragment_positions[ i + 1 ]; total_hard_fragments += ( pos - 1 ) * ( next_pos - pos ); } printf( "%lld", total_hard_fragments ); } int main() { char word[ MAX_WORD_SIZE ]; bool vowels[ MAX_ASCII_SIZE ]; initialize_vowels( vowels ); fgets( word, MAX_WORD_SIZE, stdin ); solve( word, vowels ); 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 | # include <cstdio> const int MAX_WORD_SIZE = 300011; const int MAX_ASCII_SIZE = 255; void initialize_vowels( bool vowels[ ] ) { for ( int i = 0; i < MAX_ASCII_SIZE; i ++ ) { vowels[ i ] = 0; } vowels[ 'a' ] = 1; vowels[ 'e' ] = 1; vowels[ 'i' ] = 1; vowels[ 'o' ] = 1; vowels[ 'u' ] = 1; vowels[ 'y' ] = 1; } void solve( char word[ ], bool vowels[ ] ) { int word_length = 0; int vowels_count = 0; int consonants_count = 0; int hard_fragment_positions[ MAX_WORD_SIZE ]; int hard_fragment_positions_size = 0; long long total_hard_fragments = 0; while ( word_length < 2 ) { if ( word[ word_length ] == '\0' ) { printf( "0" ); return; } vowels_count += vowels[ word[ word_length ] ]; consonants_count += 1 - vowels[ word[ word_length ] ]; word_length ++; } while ( word[ word_length ] != '\0' ) { vowels_count += vowels[ word[ word_length ] ]; consonants_count += 1 - vowels[ word[ word_length ] ]; if ( vowels_count == 3 || consonants_count == 3 ) { hard_fragment_positions[ hard_fragment_positions_size ] = word_length; hard_fragment_positions_size ++; } vowels_count -= vowels[ word[ word_length - 2 ] ]; consonants_count -= 1 - vowels[ word[ word_length - 2 ] ]; word_length ++; } hard_fragment_positions[ hard_fragment_positions_size ] = word_length - 1; hard_fragment_positions_size ++; for ( int i = 0; i < hard_fragment_positions_size - 1; i ++ ) { const int pos = hard_fragment_positions[ i ]; const int next_pos = hard_fragment_positions[ i + 1 ]; total_hard_fragments += ( pos - 1 ) * ( next_pos - pos ); } printf( "%lld", total_hard_fragments ); } int main() { char word[ MAX_WORD_SIZE ]; bool vowels[ MAX_ASCII_SIZE ]; initialize_vowels( vowels ); fgets( word, MAX_WORD_SIZE, stdin ); solve( word, vowels ); return 0; } |