#include<iostream>
#include<string>
using namespace std;
int main(){
int test;
cin>>test;
while(test--){
int n,roundd,chances,A,a=0,b=0,c=0,d=0,count=0;
string arr;
cin>>n;
cin>>arr;//inputs
// if(n%2==0){
// A=n/2;
// }else {
// A=(n+1)/2;
// //cout<<A;
// }
// cout<<"0A; "<<a<<"B: "<<b<<endl;
for(int i=0;i<n*2;i++){
if(i%2==0){if(arr[i]=='1'){
a++;
}}else{ if(arr[i]=='1'){
b++;
}
}
}
if(a==b){ //if tie
cout<<n*2;
}else{ roundd==0;
for(int i=0;i<n*2;i++){
if(i%2==0){ if(arr[i]=='1'){c++;}
}else{
count++;
chances=n-count;
// cout<<chances ;// chances
if(arr[i]=='1'){d++; }
if( (c>chances || d>chances) && (c!=d+chances && d!=c+chances )){
roundd=count*2;
cout<<roundd<<endl;
break;
}
}
}//for loop
}//else
//cout<<"0A; "<<c<<"B: "<<d<<endl;
//cout<<roundd<<endl;
//cout<<"error"<<endl;
}//while
return 0;
}//main
it should be visible now.
Backticks, not apostrophes!
GOOD NOW?
rectified it,still not working.
“Rectified it” how? Post your updated code.
updated [ if( (c>chances || d>chances) && (c!=d+chances && d!=c+chances ))] this part
in post(see the code above).
rectified mean,its giving correct answer for input you provided.
Consider the test input:
1
10
01011101000101100110
14? is this rit!
The correct answer for this test input is 13
.
Seems rit now, still getting WA.
#include<iostream>
#include<string>
using namespace std;
int main(){
int test;
cin>>test;
while(test--){
int n,roundd,chances,A,a=0,b=0,c=0,d=0,count=0,check=false;
string arr;
cin>>n;
cin>>arr;//inputs
// if(n%2==0){
// A=n/2;
// }else {
// A=(n+1)/2;
// //cout<<A;
// }
// cout<<"0A; "<<a<<"B: "<<b<<endl;
for(int i=0;i<n*2;i++){
if(i%2==0){if(arr[i]=='1'){
a++;
}}else{ if(arr[i]=='1'){
b++;
}
}
}
if(a==b){ //if tie
cout<<n*2;
}else{
for(int i=0;i<n*2;i++){
chances=n-count;
if(i%2==0){ if(arr[i]=='1'){c++;}
}else{
count++;
// cout<<chances ;// chances
if(arr[i]=='1'){d++;
}}
if ( c>d+chances ){
cout<<i; break;}
if(d>c+chances){ cout <<i; break ;}
}//for loop
}//else
//cout<<"0A; "<<c<<"B: "<<d<<endl;
cout<<endl;
//cout<<"error"<<endl;
}//while
return 0; }
//main
Consider the test input:
1
1
01
Now?
#include<iostream>
#include<string>
using namespace std;
int main(){
int test;
cin>>test;
while(test--){
int n,roundd,chances,A,a=0,b=0,c=0,d=0,count=0,check=false;
string arr;
cin>>n;
cin>>arr;//inputs
// if(n%2==0){
// A=n/2;
// }else {
// A=(n+1)/2;
// //cout<<A;
// }
// cout<<"0A; "<<a<<"B: "<<b<<endl;
for(int i=0;i<n*2;i++){
if(i%2==0){if(arr[i]=='1'){
a++;
}}else{ if(arr[i]=='1'){
b++;
}
}
}
if(a==b || n==1){ //if tie
cout<<n*2;
}else{
for(int i=0;i<n*2;i++){
chances=n-count;
if(i%2==0){ if(arr[i]=='1'){c++;}
}else{
count++;
// cout<<chances ;// chances
if(arr[i]=='1'){d++;
}}
if ( c>d+chances ){
cout<<i; break;}
if(d>c+chances){ cout <<i; break ;}
}//for loop
}//else
//cout<<"0A; "<<c<<"B: "<<d<<endl;
cout<<endl;
//cout<<"error"<<endl;
}//while
return 0; }
//main```
1
3
000111
good now ,Still getting WA
#include<iostream>
#include<string>
using namespace std;
int main(){
int test;
cin>>test;
while(test--){
int n,roundd,chances,A,a=0,b=0,c=0,d=0,count=0,check=false;
string arr;
cin>>n;
cin>>arr;//inputs
// if(n%2==0){
// A=n/2;
// }else {
// A=(n+1)/2;
// //cout<<A;
// }
// cout<<"0A; "<<a<<"B: "<<b<<endl;
for(int i=0;i<n*2;i++){
if(i%2==0){if(arr[i]=='1'){
a++;
}}else{ if(arr[i]=='1'){
b++; }
}
}
if(a==b){ //if tie
cout<<n*2;
}else{
for(int i=0;i<n*2;i++){
if(i%2==0){ if(arr[i]=='1'){c++;}
}else{
count++;
// cout<<chances ;// chances
if(arr[i]=='1'){d++;
}}
chances =n-count;
//cout<<chances;
if ( c>d+chances ){
cout<<i; break;}
if(d>c+chances){
cout <<count*2; break ;}
}//for loop
}//else
cout<<endl;
//cout<<"error"<<endl;
}//while
return 0; }
//main
1
9
110010100000000011
16?
#include<iostream>
#include<string>
using namespace std;
int main(){
int test;
cin>>test;
while(test--){
int n,roundd,chances,A,a=0,b=0,c=0,d=0,count=0,check=false;
string arr;
cin>>n;
cin>>arr;//inputs
// if(n%2==0){
// A=n/2;
// }else {
// A=(n+1)/2;
// //cout<<A;
// }
// cout<<"0A; "<<a<<"B: "<<b<<endl;
for(int i=0;i<n*2;i++){
if(i%2==0){if(arr[i]=='1'){
a++;
}}else{ if(arr[i]=='1'){
b++; }
}
}
if(a==b){ //if tie
cout<<n*2;
}else{
for(int i=0;i<n*2;i++){
chances =n-count;
if(i%2==0){ if(arr[i]=='1'){c++;}
}else{
count++;
if(arr[i]=='1'){d++;
}
if(d>c+chances){cout <<i; break ;}}
if ( c>d+chances ){
cout<<i; break;}
}//for loop
}//else
//cout<<"0A; "<<c<<"B: "<<d<<endl;
cout<<endl;
//cout<<"error"<<endl;
}//while
return 0; }
//main```