#include<cstdio> #include<vector> #include<algorithm> using namespace std; bool samogloska[256]; bool spolgloska[256]; const int SIZE = 200007; char in[SIZE]; bool poczatekTrudnego[SIZE]; bool sa[SIZE]; vector <pair<int, int> > fragmenty; int main() { for (int i = 0; i < 256; ++i) { samogloska[i] = false; } samogloska['a'] = true; samogloska['e'] = true; samogloska['i'] = true; samogloska['o'] = true; samogloska['u'] = true; samogloska['y'] = true; for (int i = 0; i < 256; ++i) { spolgloska[i] = not samogloska[i]; } for (int i = 0; i < SIZE; ++i) { poczatekTrudnego[i] = false; } scanf("%s", in); int n = 0; while(in[n] != 0) { sa[n] = samogloska[in[n]]; n++; } for(int i = 2; i < n; ++i) { if ( (sa[i] == sa[i-1]) && (sa[i-1] == sa[i-2]) ) poczatekTrudnego[i-2] = true; } /* int left = n; for (int i = 0; i < n; ++i) { if (!poczatekTrudnego[i]) { left = i; break; } } int right = n-1; for (int i = left; i < n; ++i) { if (poczatekTrudnego[i]) { right = min(n-1, i+1); break; } } fragmenty.push_back(make_pair(left, right)); */ int left = 0; int right; while (left < n-1) { while (poczatekTrudnego[left] && (left < n)) ++ left; right = left; while (!poczatekTrudnego[right] && (right < n)) ++right; right = min(n - 1, right + 1); fragmenty.push_back(make_pair(left, right)); left = right; } /*for (int i = 0; i < fragmenty.size(); ++i) { printf("(%i %i), ", fragmenty[i].first, fragmenty[i].second); } printf("\n"); printf("%i %i\n", left, right); */ long long wynik = 0LL; wynik = n; wynik = ((wynik+1)*wynik)/2; wynik -= (n + n - 1); for (int i = 0; i < fragmenty.size(); ++i) { int l = fragmenty[i].first; int r = fragmenty[i].second; if (r-l > 1) { long long tmp = r-l; tmp = (tmp * (tmp-1))/2; wynik -= tmp; } } printf("%lli\n", wynik); 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include<cstdio> #include<vector> #include<algorithm> using namespace std; bool samogloska[256]; bool spolgloska[256]; const int SIZE = 200007; char in[SIZE]; bool poczatekTrudnego[SIZE]; bool sa[SIZE]; vector <pair<int, int> > fragmenty; int main() { for (int i = 0; i < 256; ++i) { samogloska[i] = false; } samogloska['a'] = true; samogloska['e'] = true; samogloska['i'] = true; samogloska['o'] = true; samogloska['u'] = true; samogloska['y'] = true; for (int i = 0; i < 256; ++i) { spolgloska[i] = not samogloska[i]; } for (int i = 0; i < SIZE; ++i) { poczatekTrudnego[i] = false; } scanf("%s", in); int n = 0; while(in[n] != 0) { sa[n] = samogloska[in[n]]; n++; } for(int i = 2; i < n; ++i) { if ( (sa[i] == sa[i-1]) && (sa[i-1] == sa[i-2]) ) poczatekTrudnego[i-2] = true; } /* int left = n; for (int i = 0; i < n; ++i) { if (!poczatekTrudnego[i]) { left = i; break; } } int right = n-1; for (int i = left; i < n; ++i) { if (poczatekTrudnego[i]) { right = min(n-1, i+1); break; } } fragmenty.push_back(make_pair(left, right)); */ int left = 0; int right; while (left < n-1) { while (poczatekTrudnego[left] && (left < n)) ++ left; right = left; while (!poczatekTrudnego[right] && (right < n)) ++right; right = min(n - 1, right + 1); fragmenty.push_back(make_pair(left, right)); left = right; } /*for (int i = 0; i < fragmenty.size(); ++i) { printf("(%i %i), ", fragmenty[i].first, fragmenty[i].second); } printf("\n"); printf("%i %i\n", left, right); */ long long wynik = 0LL; wynik = n; wynik = ((wynik+1)*wynik)/2; wynik -= (n + n - 1); for (int i = 0; i < fragmenty.size(); ++i) { int l = fragmenty[i].first; int r = fragmenty[i].second; if (r-l > 1) { long long tmp = r-l; tmp = (tmp * (tmp-1))/2; wynik -= tmp; } } printf("%lli\n", wynik); return 0; } |