Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
113998 石茂诤 统计回文子串 C++ Accepted 116 MS 264 KB 925 2025-03-18 13:47:44

Tests(1/1):


Code:

#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; }