-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathLapindrome2.cpp
More file actions
62 lines (47 loc) · 996 Bytes
/
Lapindrome2.cpp
File metadata and controls
62 lines (47 loc) · 996 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/ C++ program to check if it is
// possible to split string or not
#include <bits/stdc++.h>
using namespace std;
const int MAX_CHAR = 26;
// function to check if we can spilt
// string or not
bool checkCorrectOrNot(string &s)
{
// Counter array inisialized with 0
int count[MAX_CHAR] = {0};
// Length of the string
int n = s.length();
if (n == 1)
return true;
// traverse till the middle element
// is reached
for (int i=0,j=n-1; i<j; i++,j--)
{
// First half
count[s[i]-'a']++;
// Second half
count[s[j]-'a']--;
}
// Checking if values are different
// set flag to 1
for (int i = 0; i<MAX_CHAR; i++)
if (count[i] != 0)
return false;
return true;
}
// Driver program to test above function
int main()
{
int t;
cin>>t;
while(t--){
string s;
// String to be checked
cin>>s;
if (checkCorrectOrNot(s))
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}