UVa12545

//UVa12545 - Bits Equalizer
//贪心
#include<iostream>
#define MIN(X,Y) (((X)>(Y))?(Y):(X))
using namespace std;

int main(){
	//freopen("UVa12545.in","r",stdin);
	int N, kase = 0;	
	cin>>N;
	while(N--){
		string S,T;
		int count = 0, bit[6];
		bit[0] = bit[1] = bit[2] = bit[3] = bit[4] = 0;
		cin>>S>>T;
		for(int i = 0; i<S.size(); i++){
			bit[T[i] -'0'+4]++;//all T[0]; 
			if(S[i] != T[i])
				if(S[i] == '?'){ count++; continue;}
				else {bit[S[i]-'0']++; continue;}
			bit[S[i]-'0'+2]++;//相等时候的s[0];
		}
		if(bit[2]+bit[0]+count < bit[4]){ cout<<"Case "<<++kase<<": -1
"; continue;}
		count += bit[0]+bit[1]-MIN(bit[0],bit[1]);
		cout<<"Case "<<++kase<<": "<<count<<"
";
	}
	return 0;
}
//已AC

原文地址:https://www.cnblogs.com/gwj1314/p/9444919.html