#include<iostream> #include<deque> using namespace std; bool vovel(char c) { char b[] = "aeiouy"; for (int i=0; i<6; i++) { if (b[i] == c) return true; } return false; } int words_between(int begin, int end) { return end - begin; } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; int n = (int)s.size(); long long good_cnt = 0, bad_cnt = 0; deque<int> bs; for (int i = 0; i < n-2; i++) { if (vovel(s[i]) && vovel(s[i+1]) && vovel(s[i+2])) bs.push_back(i); else if(!vovel(s[i]) && !vovel(s[i+1]) && !vovel(s[i+2])) bs.push_back(i); } for (int i = 0; i < n; i++) { while(!bs.empty() && bs.front() < i) bs.pop_front(); if (bs.empty()) { good_cnt += words_between(i, n); } else { int bad_start = bs.front(); good_cnt += words_between(i, bad_start+2); bad_cnt += words_between(bad_start+2, n); } } cout << bad_cnt << 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 | #include<iostream> #include<deque> using namespace std; bool vovel(char c) { char b[] = "aeiouy"; for (int i=0; i<6; i++) { if (b[i] == c) return true; } return false; } int words_between(int begin, int end) { return end - begin; } int main() { ios_base::sync_with_stdio(0); string s; cin >> s; int n = (int)s.size(); long long good_cnt = 0, bad_cnt = 0; deque<int> bs; for (int i = 0; i < n-2; i++) { if (vovel(s[i]) && vovel(s[i+1]) && vovel(s[i+2])) bs.push_back(i); else if(!vovel(s[i]) && !vovel(s[i+1]) && !vovel(s[i+2])) bs.push_back(i); } for (int i = 0; i < n; i++) { while(!bs.empty() && bs.front() < i) bs.pop_front(); if (bs.empty()) { good_cnt += words_between(i, n); } else { int bad_start = bs.front(); good_cnt += words_between(i, bad_start+2); bad_cnt += words_between(bad_start+2, n); } } cout << bad_cnt << endl; return 0; } |