水题
/* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; const int MAX_LEN = 5009; char str[MAX_LEN]; int work() { int len = strlen(str); int ret = 0, j, k; for(int i = 0; i < len; i++) { j = i; while(j >= 0) { k = 2 * i - j; if(k >= len || str[j] != str[k]) { break; } ret++; j--; } } for(int i = 1; i < len; i++) { j = i - 1; if(str[j] != str[i]) { continue; } while(j >= 0) { k = 2 * i - 1 - j; if(k >= len || str[j] != str[k]) { break; } ret++; j--; } } return ret; } int main() { while(scanf("%s", str) == 1) { printf("%d ", work()); } return 0; }