#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define MAXN 200001
char word[MAXN];
enum character {
VOWEL,
CONSONANT
};
character whatCharacter(char c) {
switch(c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
return VOWEL;
default:
return CONSONANT;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.getline(word, MAXN);
int n = strlen(word);
if(n < 3) {
cout << 0 << endl;
return 0;
}
vector<int> p;
vector<int> q;
unsigned long long result = 0;
for(int i = 0; i < n-2; ++i) {
character a = whatCharacter(word[i]),
b = whatCharacter(word[i+1]),
c = whatCharacter(word[i+2]);
if(a == b && b == c) {
p.push_back(i+1);
q.push_back(i+3);
}
}
int k = p.size();
if(k == 0){
cout << 0 << endl;
return 0;
}
for(int i = 0; i < k-1; ++i) {
result += p[i] * (q[i+1] - q[i]);
}
result += p[k-1] * (n - q[k-1] + 1);
cout << 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <iostream> #include "bits/stdc++.h" using namespace std; #define MAXN 200001 char word[MAXN]; enum character { VOWEL, CONSONANT }; character whatCharacter(char c) { switch(c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return VOWEL; default: return CONSONANT; } } int main() { ios_base::sync_with_stdio(0); cin.getline(word, MAXN); int n = strlen(word); if(n < 3) { cout << 0 << endl; return 0; } vector<int> p; vector<int> q; unsigned long long result = 0; for(int i = 0; i < n-2; ++i) { character a = whatCharacter(word[i]), b = whatCharacter(word[i+1]), c = whatCharacter(word[i+2]); if(a == b && b == c) { p.push_back(i+1); q.push_back(i+3); } } int k = p.size(); if(k == 0){ cout << 0 << endl; return 0; } for(int i = 0; i < k-1; ++i) { result += p[i] * (q[i+1] - q[i]); } result += p[k-1] * (n - q[k-1] + 1); cout << result; return 0; } |
English