#include<stdio.h> #include<string.h> char buffer[200000]; #define is_vowel(x) (x)=='a'||(x)=='e'||(x)=='i'||(x)=='o'||(x)=='u'||(x)=='y' int main() { int sliding_window = 0, length, last_match = 0; int vowel = 0; unsigned long long result = 0; scanf("%s", buffer); length = strlen(buffer); for(int i=0; i<length; i++) { if(is_vowel(buffer[i])) { if(vowel) sliding_window++; else sliding_window = 1; vowel = 1; } else { if(vowel) sliding_window = 1; else sliding_window++; vowel = 0; } if(sliding_window>3) sliding_window=3; if(sliding_window ==3) { result++; result+=i-2-last_match+length-i-1+((i-2-last_match)*(length-i-1)); last_match = i-1; } } printf("%llu", result); 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 | #include<stdio.h> #include<string.h> char buffer[200000]; #define is_vowel(x) (x)=='a'||(x)=='e'||(x)=='i'||(x)=='o'||(x)=='u'||(x)=='y' int main() { int sliding_window = 0, length, last_match = 0; int vowel = 0; unsigned long long result = 0; scanf("%s", buffer); length = strlen(buffer); for(int i=0; i<length; i++) { if(is_vowel(buffer[i])) { if(vowel) sliding_window++; else sliding_window = 1; vowel = 1; } else { if(vowel) sliding_window = 1; else sliding_window++; vowel = 0; } if(sliding_window>3) sliding_window=3; if(sliding_window ==3) { result++; result+=i-2-last_match+length-i-1+((i-2-last_match)*(length-i-1)); last_match = i-1; } } printf("%llu", result); return 0; } |