从这位牛上面学到的 http://acm.lilingfei.com/uva-12545-bits-equalizer-%E4%B9%A0%E9%A2%988-3_98
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int maxn = 100+5;
char s1[maxn], s2[maxn];
int T;
int main()
{
int Case = 0;
scanf("%d", &T);
while(T--) {
memset(s1, 0, sizeof(s1));
memset(s2, 0, sizeof(s2));
int o_z = 0, z_o = 0, x_o = 0, x_z = 0;
scanf("%s", s1);
scanf("%s", s2);
for(int i = 0; i < strlen(s1); ++i) {
if(s1[i] == '1' && s2[i] == '0') ++o_z;
if(s1[i] == '0' && s2[i] == '1') ++z_o;
if(s1[i] == '?' && s2[i] == '0') ++x_z;
if(s1[i] == '?' && s2[i] == '1') ++x_o;
}
int ans = 0;
while(o_z && z_o) --o_z, --z_o, ++ans;
while(o_z && x_o) --o_z, x_o --, ans += 2;
if(o_z) ans = -1;
else ans += z_o + x_o + x_z;
printf("Case %d: %d\n", ++Case, ans);
}
return 0;
}
/**
01??00
001010
**/