#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define PB push_back
#define ST first
#define ND second
class Solver {
string text;
public:
bool isVowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y';
}
void readInput() {
cin >> text;
}
void solve() {
int n = text.size();
if(n < 3) {
cout << 0 << '\n';
return;
}
int vowels = 0, lastHard = -1;
for(int i=0;i<3;i++) {
if (isVowel(text[i])) vowels++;
}
LL result = 0;
if(vowels == 0 || vowels == 3) {
result += n - 2;
lastHard = 0;
}
for(int i=1;i<n-2;i++) {
if(isVowel(text[i - 1])) vowels--;
if(isVowel(text[i + 2])) vowels++;
if(vowels == 0 || vowels == 3) {
result += ((LL) n - 2 - i) * (i - lastHard);
lastHard = i;
}
}
cout << result << '\n';
}
};
int main() {
ios_base::sync_with_stdio(0);
Solver solver;
solver.readInput();
solver.solve();
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 | #include<cstdio> #include<iostream> #include<algorithm> #include<string> #include<vector> #include<set> #include<cmath> using namespace std; typedef vector<int> VI; typedef long long LL; #define FOR(x, b, e) for(int x=b; x<=(e); ++x) #define FORD(x, b, e) for(int x=b; x>=(e); --x) #define REP(x, n) for(int x=0; x<(n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second class Solver { string text; public: bool isVowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } void readInput() { cin >> text; } void solve() { int n = text.size(); if(n < 3) { cout << 0 << '\n'; return; } int vowels = 0, lastHard = -1; for(int i=0;i<3;i++) { if (isVowel(text[i])) vowels++; } LL result = 0; if(vowels == 0 || vowels == 3) { result += n - 2; lastHard = 0; } for(int i=1;i<n-2;i++) { if(isVowel(text[i - 1])) vowels--; if(isVowel(text[i + 2])) vowels++; if(vowels == 0 || vowels == 3) { result += ((LL) n - 2 - i) * (i - lastHard); lastHard = i; } } cout << result << '\n'; } }; int main() { ios_base::sync_with_stdio(0); Solver solver; solver.readInput(); solver.solve(); return 0; } |
English