-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquareString.cpp
More file actions
46 lines (41 loc) · 790 Bytes
/
SquareString.cpp
File metadata and controls
46 lines (41 loc) · 790 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
42
43
44
45
46
/*
Problem statement:
A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square.
But the strings "aaa", "abaaab" and "abcdabc" are not square.
For a given string s determine if it is square.
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
if (s.length() % 2 == 1) {
cout << "NO\n";
}
else {
int len = s.length();
int x = 0, y = 0;
x = 0;
y = len / 2;
bool flag = false;
while (x < (len / 2) && y < len) {
if (s[x] != s[y]) {
flag = true;
}
x++;
y++;
}
if (flag)
cout << "NO\n";
else {
cout << "YES\n";
}
}
}
return 0;
}