#include <stdio.h> #include <assert.h> #define STR_MAX_LENGTH 200001 char str[STR_MAX_LENGTH]; inline bool isAloneSound(const char &c){ return c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'; } inline unsigned long long int calc(const char str[]){ unsigned long long int response=0,ending=0; if(str[1]==0 || str[2]==0) return 0; bool isAloneSound_2; bool isAloneSound_1=isAloneSound(str[0]); bool isAloneSound_0=isAloneSound(str[1]); for(int i=2;str[i];i++){ isAloneSound_2=isAloneSound_1; isAloneSound_1=isAloneSound_0; isAloneSound_0=isAloneSound(str[i]); int s=isAloneSound_2+isAloneSound_1+isAloneSound_0; if(s==0 || s==3) ending=i-1; response+=ending; } return response; } int main(){ //testy /*assert(calc("a")==0); assert(calc("aa")==0); assert(calc("aaa")==1); assert(calc("aaaa")==3); assert(calc("aaaaa")==6); assert(calc("kostka")==6); assert(calc("aacccacccaa")==33);*/ scanf("%s",str); printf("%llu\n",calc(str)); }
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 | #include <stdio.h> #include <assert.h> #define STR_MAX_LENGTH 200001 char str[STR_MAX_LENGTH]; inline bool isAloneSound(const char &c){ return c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y'; } inline unsigned long long int calc(const char str[]){ unsigned long long int response=0,ending=0; if(str[1]==0 || str[2]==0) return 0; bool isAloneSound_2; bool isAloneSound_1=isAloneSound(str[0]); bool isAloneSound_0=isAloneSound(str[1]); for(int i=2;str[i];i++){ isAloneSound_2=isAloneSound_1; isAloneSound_1=isAloneSound_0; isAloneSound_0=isAloneSound(str[i]); int s=isAloneSound_2+isAloneSound_1+isAloneSound_0; if(s==0 || s==3) ending=i-1; response+=ending; } return response; } int main(){ //testy /*assert(calc("a")==0); assert(calc("aa")==0); assert(calc("aaa")==1); assert(calc("aaaa")==3); assert(calc("aaaaa")==6); assert(calc("kostka")==6); assert(calc("aacccacccaa")==33);*/ scanf("%s",str); printf("%llu\n",calc(str)); } |