标签:mat math.h clu 回文 namespace 子串 == include int
#include <math.h> #include <stdio.h> #include <iostream> #include <string> using namespace std; int lengthRev(string str) { int n = str.length(); int MAX = 1; int b; int e; int c = 0; for (int i = 0; i < n; i++) { b = i; e = i; c = 0; while (e + 1 < n && str[e + 1] == str[b]) e++; i = e; while (b - c >= 0 && e + c < n && str[b - c] == str[e + c]) c++; if (2 * (c - 1) + e - b + 1 > MAX) MAX = 2 * (c - 1) + e - b + 1; } return MAX; } int main() { int n; cin >> n; string s; while (n--) { cin >> s; cout << lengthRev(s) << endl; } return 0; }
标签:mat math.h clu 回文 namespace 子串 == include int
原文地址:https://www.cnblogs.com/tangjicheng/p/9146777.html