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
| #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=210; char s[maxn],s0[maxn]; int solve(int n){ int sum,_0_1,_1_0,_1_q,_0_q,cnt; sum=_1_0=_0_1=_1_q=_0_q=cnt=0; for(int i=0;i<n;++i){ if(s0[i]=='1'&&s[i]=='?') ++sum,++_1_q; if(s0[i]=='0'&&s[i]=='?') ++sum,++_0_q; if(s0[i]=='1'&&s[i]=='0') ++sum,++_1_0; if(s0[i]=='0'&&s[i]=='1') ++sum,++_0_1; } int t=min(_1_0,_0_1); cnt+=t,_0_1-=t,sum-=2*t; t=min(_1_q,_0_1); cnt+=2*t,_0_1-=t,sum-=2*t; if(_0_1) return -1; return cnt+sum; } int main(){ int t,tt=0; scanf("%d",&t); while(t--){ scanf("%s%s",s,s0); printf("Case %d: %d\n",++tt,solve((int)strlen(s0))); } return 0; }
|