#include<stdio.h> #include<strings.h> #include <iostream> #include <string> using namespace std; bool vowel(char c) { char v[] = {'a','i','e','o','u','y'}; for(int i=0; i<6; i++) { if (c==v[i]) return true; } return false; } bool hard1(string& l, int i) { size_t n = l.size(); if (i+2>=n) return 0; bool v1 = vowel(l[i]); bool v2 = vowel(l[i+1]); bool v3 = vowel(l[i+2]); return (v1 && v2 && v3); } bool hard2(string& l, int i) { size_t n = l.size(); if (i+2>=n) return 0; bool v1 = vowel(l[i]); bool v2 = vowel(l[i+1]); bool v3 = vowel(l[i+2]); return (!v1 && !v2 && !v3); } int main() { string line; getline(cin, line); long n = line.size(); if (n<3) { cout<< 0 << endl; return 0; } long c = (1+n)*n/2; long easy_count = 0; long i = 0; while(i<n) { bool h1 = hard1(line, i); bool h2 = hard2(line, i); if (h1 || h2) { bool (*hard)(string&, int) = (h1)? hard1: hard2; long hl = i; while (hard(line, i) && i<n) i += 1; hl = i-hl+2; long singles = hl-4; if (singles<0) singles=0; c -= singles; long doubles = (hl>3)? (singles+1): 0; c -= doubles; if (hl==3) c += 1; easy_count += 2; c -= easy_count*(easy_count+1)/2; easy_count = 0; i -= 1; } else { easy_count += 1; } i += 1; }; c -= easy_count*(easy_count+1)/2; cout << c << endl; 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 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include<stdio.h> #include<strings.h> #include <iostream> #include <string> using namespace std; bool vowel(char c) { char v[] = {'a','i','e','o','u','y'}; for(int i=0; i<6; i++) { if (c==v[i]) return true; } return false; } bool hard1(string& l, int i) { size_t n = l.size(); if (i+2>=n) return 0; bool v1 = vowel(l[i]); bool v2 = vowel(l[i+1]); bool v3 = vowel(l[i+2]); return (v1 && v2 && v3); } bool hard2(string& l, int i) { size_t n = l.size(); if (i+2>=n) return 0; bool v1 = vowel(l[i]); bool v2 = vowel(l[i+1]); bool v3 = vowel(l[i+2]); return (!v1 && !v2 && !v3); } int main() { string line; getline(cin, line); long n = line.size(); if (n<3) { cout<< 0 << endl; return 0; } long c = (1+n)*n/2; long easy_count = 0; long i = 0; while(i<n) { bool h1 = hard1(line, i); bool h2 = hard2(line, i); if (h1 || h2) { bool (*hard)(string&, int) = (h1)? hard1: hard2; long hl = i; while (hard(line, i) && i<n) i += 1; hl = i-hl+2; long singles = hl-4; if (singles<0) singles=0; c -= singles; long doubles = (hl>3)? (singles+1): 0; c -= doubles; if (hl==3) c += 1; easy_count += 2; c -= easy_count*(easy_count+1)/2; easy_count = 0; i -= 1; } else { easy_count += 1; } i += 1; }; c -= easy_count*(easy_count+1)/2; cout << c << endl; return 0; } |