Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
55 | 晁鑫 | 统计回文子串 | C++ | Accepted | 136 MS | 756 KB | 925 | 2020-08-10 14:54:28 |
#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N = 5001; char str[N]; int solve() { int ans = 0, len = strlen(str); for ( int i = 0; i < len; i++ ) { for ( int j = 0; i - j >= 0 && i + j < len; j++ ) { if ( str[i - j] == str[i + j] ) { ans++; } else { break; } } if ( str[i] != str[i + 1] ) continue; for ( int j = 0; i - j >= 0 && i + 1 + j < len; j++ ) { if ( str[i - j] == str[i + 1 + j] ) { ans++; } else { break; } } } return ans; } int main () { while ( scanf("%s", str) != EOF ) { printf("%d\n", solve()); } return 0; }