#include <cstdio> using namespace std; // "abcdefghijklmnopqrstuvwxyz"; const char mask[] = "01110111011111011111011101"; const int N = 200009; char s[N]; long long solve() { scanf("%s", s); if (s[1] == 0) return 0; if (s[2] == 0) return 0; s[0] -= 'a'; s[1] -= 'a'; int pos = 0; long long res = 0; for (int i = 2; s[i]; ++i) { s[i] -= 'a'; if (mask[s[i]] == mask[s[i - 1]] && mask[s[i]] == mask[s[i - 2]]) pos = i - 1; res += pos; } return res; } int main() { printf("%lld\n", solve()); 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 | #include <cstdio> using namespace std; // "abcdefghijklmnopqrstuvwxyz"; const char mask[] = "01110111011111011111011101"; const int N = 200009; char s[N]; long long solve() { scanf("%s", s); if (s[1] == 0) return 0; if (s[2] == 0) return 0; s[0] -= 'a'; s[1] -= 'a'; int pos = 0; long long res = 0; for (int i = 2; s[i]; ++i) { s[i] -= 'a'; if (mask[s[i]] == mask[s[i - 1]] && mask[s[i]] == mask[s[i - 2]]) pos = i - 1; res += pos; } return res; } int main() { printf("%lld\n", solve()); return 0; } |