#include <iostream> #include <cstdio> #include <cmath> #define MAX_DLUGOSC 200001 using namespace std; bool isSamogloska(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } bool isTheSame(char c1, char c2, char c3) { return (isSamogloska(c1) && isSamogloska(c2) && isSamogloska(c3)) || (!isSamogloska(c1) && !isSamogloska(c2) && !isSamogloska(c3)); } int max(int a, int b) { if (a > b) return a; else return b; } int main() { char s[MAX_DLUGOSC + 1]; int i; scanf("%s", s); long long int result = 0; //cout << s << endl; int start3 = 0; int end3 = 0; bool currentTheSame = false; if (s[1] == 0 || s[2] == 0) { cout << 0 << endl; return 0; } for (i = 2; s[i] != 0; i++) { if (isTheSame(s[i - 2], s[i - 1], s[i])) { if (!currentTheSame) { currentTheSame = true; start3 = i - 2; long long int n = (start3 + 2) - max(0, end3 - 2); result += n*(n + 1) / 2 - n - (n - 1); } } else //!isTheSame { if (currentTheSame) { currentTheSame = false; end3 = i; } } //cout << "i: " << i << " start3: " << start3 << " end3: " << end3 << " result: " << result << endl; } if (currentTheSame) end3 = i; long long int length = i; long long int n = i - end3 + 2; result += n*(n + 1) / 2 - n - (n - 1); result = length * (length + 1) / 2 - length - (length - 1) - result; if (result < 0) result = 0; cout << result << 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <iostream> #include <cstdio> #include <cmath> #define MAX_DLUGOSC 200001 using namespace std; bool isSamogloska(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'; } bool isTheSame(char c1, char c2, char c3) { return (isSamogloska(c1) && isSamogloska(c2) && isSamogloska(c3)) || (!isSamogloska(c1) && !isSamogloska(c2) && !isSamogloska(c3)); } int max(int a, int b) { if (a > b) return a; else return b; } int main() { char s[MAX_DLUGOSC + 1]; int i; scanf("%s", s); long long int result = 0; //cout << s << endl; int start3 = 0; int end3 = 0; bool currentTheSame = false; if (s[1] == 0 || s[2] == 0) { cout << 0 << endl; return 0; } for (i = 2; s[i] != 0; i++) { if (isTheSame(s[i - 2], s[i - 1], s[i])) { if (!currentTheSame) { currentTheSame = true; start3 = i - 2; long long int n = (start3 + 2) - max(0, end3 - 2); result += n*(n + 1) / 2 - n - (n - 1); } } else //!isTheSame { if (currentTheSame) { currentTheSame = false; end3 = i; } } //cout << "i: " << i << " start3: " << start3 << " end3: " << end3 << " result: " << result << endl; } if (currentTheSame) end3 = i; long long int length = i; long long int n = i - end3 + 2; result += n*(n + 1) / 2 - n - (n - 1); result = length * (length + 1) / 2 - length - (length - 1) - result; if (result < 0) result = 0; cout << result << endl; return 0; } |