Day 25 of 100 days of code
Today, I successfully tackled two CodeChef problems.
#include <bits/stdc++.h>
using namespace std;
bool solve(int n){
int sum=0;
for(int i =0;i<n;i++){
int x;
cin>>x;
sum+=x;
}
return (sum%2==1);
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(solve(n)){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
}
#include <bits/stdc++.h>
using namespace std;
bool solve(string a,string b){
int x = count(a.begin(),a.end(),'1');
int y = count(b.begin(),b.end(),'1');
return x==y;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string a;
cin>>a;
string b;
cin>>b;
if(solve(a,b)){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
}
ย