现在的位置: 首页 > 综合 > 正文

UVA – 12545 (细心)

2019年04月04日 ⁄ 综合 ⁄ 共 658字 ⁄ 字号 评论关闭
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

const int maxn = 210;
char str[maxn],src[maxn];
int main()
{
    int T;
    scanf("%d",&T);
    for(int kase=1;kase<=T;kase++){
        scanf("%s%s",str,src);
        printf("Case %d: ",kase);
        int n=strlen(str),m=strlen(src);
        if(n!=m) {printf("-1\n"); continue; }
        int key1=0,key0=0,zero=0,one=0;
        for(int i=0;i<n;i++){
              if(str[i]=='?'){ if(src[i]=='1') key1++; if(src[i]=='0') key0++;}
              if(str[i]=='0'&&src[i]=='1') zero++;
              if(str[i]=='1'&&src[i]=='0') one++;
        }
        if(zero>=one){
            printf("%d\n",zero+key0+key1);
        }
        else {
            if(zero+key1<one) {
                printf("-1\n");
            }
            else{
                printf("%d\n",one+key1+key0);
            }
        }
    }
    return 0;
}

抱歉!评论已关闭.