#include <stdio.h> #include <string.h> char line[300000]; unsigned char sam[] = "aeiouy"; unsigned char letters[] ="qwertyuiopasdfghjklzxcvbnm"; int type[256]; int main() { scanf("%s",line); long long int n = strlen(line); for(int i = 0; i < 26; ++i){ type[letters[i]] = (letters[i] == 'a' || letters[i] == 'e' || letters[i] == 'i' || letters[i] == 'o' || letters[i] == 'u' || letters[i] == 'y'); } int totalLetter = 0; int flag = 0; long long int last = -1; long long int total = n * (n + 1) / 2; for(long long int i = 0; i < n; ++i){ if ((type[(unsigned char)line[i]] && flag) || (type[(unsigned char)line[i]] == 0 && flag == 0)) ++totalLetter; else { flag = type[(unsigned char)line[i]]; totalLetter = 1; } if (totalLetter >= 3) last = i - 2; // printf("%d %d\n",last , i); // if (totalLetter < 3) total -= (i - last); } printf("%lld\n",total); 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 | #include <stdio.h> #include <string.h> char line[300000]; unsigned char sam[] = "aeiouy"; unsigned char letters[] ="qwertyuiopasdfghjklzxcvbnm"; int type[256]; int main() { scanf("%s",line); long long int n = strlen(line); for(int i = 0; i < 26; ++i){ type[letters[i]] = (letters[i] == 'a' || letters[i] == 'e' || letters[i] == 'i' || letters[i] == 'o' || letters[i] == 'u' || letters[i] == 'y'); } int totalLetter = 0; int flag = 0; long long int last = -1; long long int total = n * (n + 1) / 2; for(long long int i = 0; i < n; ++i){ if ((type[(unsigned char)line[i]] && flag) || (type[(unsigned char)line[i]] == 0 && flag == 0)) ++totalLetter; else { flag = type[(unsigned char)line[i]]; totalLetter = 1; } if (totalLetter >= 3) last = i - 2; // printf("%d %d\n",last , i); // if (totalLetter < 3) total -= (i - last); } printf("%lld\n",total); return 0; } |