#include <iostream> #include <string> using namespace std; bool is_cons(char c) { return (c == 'a') || (c == 'o') || (c == 'e') || (c == 'y') || (c == 'u') || (c == 'i') ; }; int main() { string s; getline(cin, s); int n = s.length(); for (int i=0; i<n; i++) { if (is_cons(s[i])) s[i] = 'a'; else s[i] = 'b'; } long ret = 0; int begin = 0; for (int l=0; l<n-2; l++) { int p = l+3; if ((s[l] == s[l+1]) && (s[l] == s[l+2])) { ret += (l-begin+1) * (n-p+1); begin = l+1; } } cout << ret << 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 | #include <iostream> #include <string> using namespace std; bool is_cons(char c) { return (c == 'a') || (c == 'o') || (c == 'e') || (c == 'y') || (c == 'u') || (c == 'i') ; }; int main() { string s; getline(cin, s); int n = s.length(); for (int i=0; i<n; i++) { if (is_cons(s[i])) s[i] = 'a'; else s[i] = 'b'; } long ret = 0; int begin = 0; for (int l=0; l<n-2; l++) { int p = l+3; if ((s[l] == s[l+1]) && (s[l] == s[l+2])) { ret += (l-begin+1) * (n-p+1); begin = l+1; } } cout << ret << endl; return 0; } |