#include <cstdio> #define max(_a_, _b_) (_a_) > (_b_) ? (_a_) : (_b_) using namespace std; static char ch[2000001]; char sam(char ch) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'; } bool spol(char ch) { return !sam(ch); } int main() { scanf("%s", ch); char b1 = ch[0]; char b2 = ch[1]; unsigned long sum = 0; int len = 0; for (int i = 0; ch[i] != '\0'; i++) { len++; } int last = 0; for (int i = 2; ch[i] != '\0'; i++) { if (sam(b1) && sam(b2) && sam(ch[i]) || spol(b1) && spol(b2) && spol(ch[i])) { int before = max(0, i - 2 - last); int after = len - i - 1; sum += before + 1 + after + (before * after); //printf("%c %c %c, before: %d, after: %d, sum:%lu\n", b1, b2, ch[i], before, after, sum); last = i - 1; } b1 = b2; b2 = ch[i]; } printf("%lu\n", sum); 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 | #include <cstdio> #define max(_a_, _b_) (_a_) > (_b_) ? (_a_) : (_b_) using namespace std; static char ch[2000001]; char sam(char ch) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'; } bool spol(char ch) { return !sam(ch); } int main() { scanf("%s", ch); char b1 = ch[0]; char b2 = ch[1]; unsigned long sum = 0; int len = 0; for (int i = 0; ch[i] != '\0'; i++) { len++; } int last = 0; for (int i = 2; ch[i] != '\0'; i++) { if (sam(b1) && sam(b2) && sam(ch[i]) || spol(b1) && spol(b2) && spol(ch[i])) { int before = max(0, i - 2 - last); int after = len - i - 1; sum += before + 1 + after + (before * after); //printf("%c %c %c, before: %d, after: %d, sum:%lu\n", b1, b2, ch[i], before, after, sum); last = i - 1; } b1 = b2; b2 = ch[i]; } printf("%lu\n", sum); return 0; } |