#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
int a, b;
char c;
cin>>a;
for(int i=0; i<a; i++)
{
int x=0, z=0, s=0;
cin>>b;
for(int j=1; j<=b; j++)
{
cin>>c;
if(c=='1')
{
z=1;
}
else
{
x++;
s=1;
}
}
if(z==1 && s==1)
{
cout<<x<<endl;
}
if(z==0) cout<<"0"<<endl;
if(s==0) cout<<b<<endl;
}
return 0;
}
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 | #include <iostream> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(); int a, b; char c; cin>>a; for(int i=0; i<a; i++) { int x=0, z=0, s=0; cin>>b; for(int j=1; j<=b; j++) { cin>>c; if(c=='1') { z=1; } else { x++; s=1; } } if(z==1 && s==1) { cout<<x<<endl; } if(z==0) cout<<"0"<<endl; if(s==0) cout<<b<<endl; } return 0; } |
English