-
Notifications
You must be signed in to change notification settings - Fork 0
/
XORpalidrome.cpp
50 lines (42 loc) · 894 Bytes
/
XORpalidrome.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int cnt0=0,cnt1=0;
for(int i=0;i<n;i++){
if(s[i]=='0'){
cnt0++;
}else{
cnt1++;
}
}
bool isPossible=false;
if(n%2==1){
if(cnt1%2==0 || cnt0%2==0){
isPossible=true;
}else{
isPossible=false;
}
}else{
if(cnt1==cnt0){
isPossible=true;
}else if(cnt1==0 || cnt0==0){
isPossible=true;
}else{
isPossible=false;
}
}
if(isPossible){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
}