#include <cstdio> #include <cstring> #include <vector> char napis[200005]; int n; bool samogloska[26]; std::vector<int> v; int main(){ scanf("%s", napis); n = strlen(napis); long long res = (long long)n * (n - 1) / 2; for (int i = 0; i < 26; i++){ samogloska[i] = false; } samogloska['a' - 'a'] = true; samogloska['e' - 'a'] = true; samogloska['i' - 'a'] = true; samogloska['o' - 'a'] = true; samogloska['u' - 'a'] = true; samogloska['y' - 'a'] = true; v.push_back(-1); for (int i = 0; i <= n - 3; i++){ if ((samogloska[napis[i] - 'a']) && (samogloska[napis[i + 1] - 'a']) && (samogloska[napis[i + 2] - 'a'])){ v.push_back(i); } if ((!samogloska[napis[i] - 'a']) && (!samogloska[napis[i + 1] - 'a']) && (!samogloska[napis[i + 2] - 'a'])){ v.push_back(i); } } v.push_back(n - 2); for (int i = 0; i < (int)v.size() - 1; i++){ res -= (long long)(v[i + 1] + 1 - v[i]) * (v[i + 1] + 1 - v[i] - 1) / 2; } printf("%lld", res); }
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 | #include <cstdio> #include <cstring> #include <vector> char napis[200005]; int n; bool samogloska[26]; std::vector<int> v; int main(){ scanf("%s", napis); n = strlen(napis); long long res = (long long)n * (n - 1) / 2; for (int i = 0; i < 26; i++){ samogloska[i] = false; } samogloska['a' - 'a'] = true; samogloska['e' - 'a'] = true; samogloska['i' - 'a'] = true; samogloska['o' - 'a'] = true; samogloska['u' - 'a'] = true; samogloska['y' - 'a'] = true; v.push_back(-1); for (int i = 0; i <= n - 3; i++){ if ((samogloska[napis[i] - 'a']) && (samogloska[napis[i + 1] - 'a']) && (samogloska[napis[i + 2] - 'a'])){ v.push_back(i); } if ((!samogloska[napis[i] - 'a']) && (!samogloska[napis[i + 1] - 'a']) && (!samogloska[napis[i + 2] - 'a'])){ v.push_back(i); } } v.push_back(n - 2); for (int i = 0; i < (int)v.size() - 1; i++){ res -= (long long)(v[i + 1] + 1 - v[i]) * (v[i + 1] + 1 - v[i] - 1) / 2; } printf("%lld", res); } |