-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1802.cpp
More file actions
41 lines (33 loc) · 829 Bytes
/
boj1802.cpp
File metadata and controls
41 lines (33 loc) · 829 Bytes
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>
using namespace std;
bool calc(int start, int end, string& info){
if(end <= start) return true;
int mid = (start + end) / 2;
int left = start;
int right = end;
while(left<right){
if(info[left++]==info[right--]){
return false;
}
}
int leftResult = calc(start, mid-1, info);
int rightResult = calc(mid+1, end, info);
return leftResult && rightResult;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
string info;
cin>>info;
int length = (int)info.length();
bool possible = calc(0, length-1, info);
if(possible) cout<<"YES";
else cout<<"NO";
cout<<'\n';
}
return 0;
}