UVa12545 - Bits Equalizer

时间:2023-02-08 15:00:03


//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\n"; continue;}
count += bit[0]+bit[1]-MIN(bit[0],bit[1]);
cout<<"Case "<<++kase<<": "<<count<<"\n";
}
return 0;
}
//已AC