uva6152Bits Equalizer

简介: View Code 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define DEBUG 8 int min(int a, int ...
View Code
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string>
 4 #include <math.h>
 5 #include <algorithm>
 6 using namespace std;
 7 #define DEBUG
 8 int min(int a, int b){
 9     return a<b?a:b;
10 }
11 int main(){
12 #ifndef DEBUG
13     freopen("in.txt", "r", stdin);
14 #endif
15     int cas;
16     scanf("%d", &cas);
17     int id=1;
18     while(cas--){
19         string s, t;
20         cin >> s >> t;
21         printf("Case %d: ",id++);
22         int i, ans=0;
23         int cnt1, cnt2, cnt3, cnt4, cnt5, cnt6;
24         cnt1=count(s.begin(), s.end(), '0');
25         cnt2=count(s.begin(), s.end(), '?');
26         cnt3=count(t.begin(), t.end(), '0');
27         if(cnt1+cnt2<cnt3){
28             printf("%d\n", -1);
29             continue;
30         }
31         cnt4=0;
32         cnt5=0;
33         ans+=cnt2;
34         for(i=0; i<s.length(); i++){
35             if(s[i]=='0' && t[i]=='1') cnt4++;
36             else if(s[i]=='1' && t[i]=='0') cnt5++;
37         }
38         ans+=min(cnt4, cnt5);
39         cnt6=abs(cnt4-cnt5);
40         ans+=cnt6;
41         printf("%d\n", ans);
42     }
43     return 0;
44 }

题目很简答,题意就不说了。

这里值得说的是,stl的count函数在这里可以用一下~

目录
相关文章
uva127 "Accordian" Patience
uva127 "Accordian" Patience
43 0
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
42 0
POJ 2840 Big Clock
POJ 2840 Big Clock
113 0
POJ 2840 Big Clock
Description Our vicar raised money to have the church clock repaired for several weeks. The big clock, which used to strike the hours days...
929 0
|
C++
UVA 之10010 - Where's Waldorf?
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/24863879 ...
713 0
|
机器学习/深度学习
uva 11538 Chess Queen
点击打开链接 题意:给定一个n*m的矩阵,问有多少种方法放置两个相互攻击的皇后?规定在同一行同一列和同对角线的能够相互攻击 思路: 1 先考虑同一行的情况,n行就有n种情况,每一行有m*(m-1)种,总的是n*m*(m-1); 2 考虑同...
819 0
|
机器学习/深度学习 CDN
|
机器学习/深度学习
uva 12470 Tribonacci
点击打开uva12470  思路: 矩阵快速幂 分析: 1 裸题 代码: /************************************************ * By: chenguolin ...
993 0
下一篇
DataWorks