-
Notifications
You must be signed in to change notification settings - Fork 0
/
CON5_6.cpp
85 lines (83 loc) · 1.86 KB
/
CON5_6.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
/*
void check(string s){
int n = s.size();
int ans = 1;
vector<vector<int>> a(n, vector<int>(n));
for (int i = 0; i < n; i++)
a[i][i] = 1;
for (int i = 1; i < n; i++){
for (int j = 0; j < n - i; j++){
int x = i + j;
if ((j + 1 > x - 1 || a[j + 1][x - 1]) && s[j] == s[x]){
a[j][x] = 1;
}else{
a[j][x] = 0;
}
if (a[j][x])
ans = i + 1;
}
}
cout<<ans<<endl;
}
int main(){
int t; cin >> t;
while(t--){
string s; cin >> s;
check(s);
}
}
*/
void check(string s){
int n = s.size();
int ans = 1;
vector<vector<int>> temp(n, vector<int>(n));
for (int i = 0; i < n; i++){
temp[i][i] = 1;
}
for (int i = 2; i <= n; i++){ // // test Lỏ ko có dấu = ở 2 vòng lặp vẫn đúng :D
for (int j = 0; j <= n - i; j++){
int x = i + j - 1;
if ((j + 1 > x - 1 || temp[j + 1][x - 1]) && s[j] == s[x]){
temp[j][x] = 1;
}
if(temp[j][x]){
ans = i;
}
}
}
cout<<ans<<endl;
}
/*
void check(string s){
int n = s.size();
int ans = 1;
vector<vector<int>> temp(n, vector<int>(n));
for (int i = 0; i < n; i++){
temp[i][i] = 1;
}
for (int i = 2; i <= n; i++){
for (int j = 0; j <= n - i; j++){
int x = i + j - 1;
if (i == 2 && s[j] == s[x]){
temp[j][x] = 1;
}
if (temp[j + 1][x - 1] && s[j] == s[x]){
temp[j][x] = 1;
}
if(temp[j][x]){
ans = i;
}
}
}
cout<<ans<<endl;
}
*/
int main(){
int t; cin >> t;
while(t--){
string s; cin >> s;
check(s);
}
}