#include <bits/stdc++.h> using namespace std; int n; string s; bool is_samo[26] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}; int main () { cin >> s; n = s.length(); long long int wynik = 0; int pop = 0; for (int i = 2; i < n; i++) { if (is_samo[s[i]-'a'] == is_samo[s[i-1]-'a'] && is_samo[s[i-1]-'a'] == is_samo[s[i-2]-'a']) { wynik += (i - 1 - pop) * (n-i); pop = i-1; } } cout << wynik; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <bits/stdc++.h> using namespace std; int n; string s; bool is_samo[26] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}; int main () { cin >> s; n = s.length(); long long int wynik = 0; int pop = 0; for (int i = 2; i < n; i++) { if (is_samo[s[i]-'a'] == is_samo[s[i-1]-'a'] && is_samo[s[i-1]-'a'] == is_samo[s[i-2]-'a']) { wynik += (i - 1 - pop) * (n-i); pop = i-1; } } cout << wynik; } |