#include<cstdio> //ABCDEFGHIJKLMNOPQRSTUVWXYZ static const char* litery = "TFFFTFFFTFFFFFTFFFFFTFFFTF"; static char str[200001]; static char typ(char z){ return litery[z - 'a']; } typedef unsigned long long ull; int main(){ scanf("%s", str); int s = -1; while(str[++s]); char sw = typ(str[0]); int licz = 1; ull suma = 0; int p = 0; for(int i = 1; i < s; ++i){ char nsw = typ(str[i]); if(nsw != sw){ sw = nsw; licz = 1; } else{ ++licz; } if(licz >= 3){ suma += ull(s-i)*ull(i - p - 1); p = i - 1; } } printf("%llu\n", suma); }
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 | #include<cstdio> //ABCDEFGHIJKLMNOPQRSTUVWXYZ static const char* litery = "TFFFTFFFTFFFFFTFFFFFTFFFTF"; static char str[200001]; static char typ(char z){ return litery[z - 'a']; } typedef unsigned long long ull; int main(){ scanf("%s", str); int s = -1; while(str[++s]); char sw = typ(str[0]); int licz = 1; ull suma = 0; int p = 0; for(int i = 1; i < s; ++i){ char nsw = typ(str[i]); if(nsw != sw){ sw = nsw; licz = 1; } else{ ++licz; } if(licz >= 3){ suma += ull(s-i)*ull(i - p - 1); p = i - 1; } } printf("%llu\n", suma); } |