#include <bits/stdc++.h> using namespace std; string s; int n; int val[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 input[200000]; long long int result = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> s; n = s.size(); for(int i = 0; i < n; i ++){ input[i] = val[s[i] - 97]; } int prelast = input[0]; int last = input[1]; long long int start = 0; for(int i = 2; i < n; i ++){ if(input[i] == prelast && input[i] == last){ result += (i - 1 - start) * (n - i); start = i - 1; } prelast = last; last = input[i]; } cout << result; 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 | #include <bits/stdc++.h> using namespace std; string s; int n; int val[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 input[200000]; long long int result = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> s; n = s.size(); for(int i = 0; i < n; i ++){ input[i] = val[s[i] - 97]; } int prelast = input[0]; int last = input[1]; long long int start = 0; for(int i = 2; i < n; i ++){ if(input[i] == prelast && input[i] == last){ result += (i - 1 - start) * (n - i); start = i - 1; } prelast = last; last = input[i]; } cout << result; return 0; } |