uva 12545 - Bits Equalizer

从这位牛上面学到的 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

**/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值