-
Notifications
You must be signed in to change notification settings - Fork 0
/
1040.cpp
41 lines (33 loc) · 907 Bytes
/
1040.cpp
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 <iostream>
#include <algorithm>
#include <string>
const int MAXN = 1000 + 10;
using namespace std;
string str;
int f[MAXN][MAXN];
int main() {
getline(cin, str);
for (int i = 0; i < str.size(); i++) {
f[i][i] = 1;
}
for (int len = 2; len <= str.size(); len++) {
for (int l = 0; l + len - 1 < str.size(); l++) {
int r = l + len - 1;
if (str[l] == str[r]) {
if (len != 2) f[l][r] = f[l + 1][r - 1];
else f[l][r] = 1;
}
else f[l][r] = 0;
}
}
int ans = 0;
for (int i = 0; i < str.size(); i++) {
for (int j = 0; j < str.size(); j++) {
if (f[i][j] == 1) ans = max(ans, j - i + 1);
// printf("%d ", f[i][j]);
}
// printf("\n");
}
printf("%d\n", ans);
return 0;
}