-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSPOJ1112.cc
39 lines (35 loc) · 849 Bytes
/
SPOJ1112.cc
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
// SPOJ 13043: The Mirror of Galadriel
// http://www.spoj.com/problems/AMR12D/
//
// Solution: String
//
// since substrings of length n string is O(n^2),
// simple method is acceptable.
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
bool solve(string s) {
set<string> S;
int n = s.size();
for (int i = 0; i < n; ++i)
for (int l = 1; i+l <= n; ++l)
S.insert( s.substr(i,l) );
for (int i = 0; i < n; ++i)
for (int l = 1; i+l <= n; ++l) {
string r = s.substr(i,l);
reverse(r.begin(), r.end());
if (S.count(r) == 0) return false;
}
return true;
}
int main() {
int T; cin >> T;
while (T--) {
string s; cin >> s;
if (solve(s)) printf("YES\n");
else printf("NO\n");
}
}