先把0变1
然后把变的这一组的_0_1与对应_1_?变
#include<bits/stdc++.h>
using namespace std;
const int maxn = 210;
char s[maxn],s0[maxn];
int solve(int n){
int sum,_0_1,_1_0,_1_q,_0_q,cnt=0;
sum=_0_1=_1_0=_1_q=_0_q=cnt=0;
for(int i=0;i<n;i++){
if(s0[i]=='1'&&s[i]=='?') ++sum,++_1_q;
if(s0[i]=='0'&&s[i]=='?') ++sum,++_0_q;
if(s0[i]=='1'&&s[i]=='0') ++sum,++_1_0;
if(s0[i]=='0'&&s[i]=='1') ++sum,++_0_1;
}
int t=min(_1_0,_0_1);
cnt+=t,_0_1-=t,sum-=2*t;
t=min(_1_q,_0_1);
cnt+=2*t,_0_1-=t,sum-=2*t;
if(_0_1) return -1;
return cnt+sum;
}
int main()
{
int t,tt=0;
scanf("%d",&t);
while(t--){
scanf("%s%s",s,s0);
printf("Case %d: %d\n",++tt,solve((int)strlen(s0)));
}
return 0;
}
find out what you passion is,what make you happy what you love doing
pursue with everything you have,work harder than anybody else
know that life doesn't always go as planed
we all have dreams,we all have visions,we can do with our lives
but there would be a lot of times when it doesn't the way we want to,
and there happens everybody,but it not realy about how
what is important is how you respon to this situations,you know
that's the persevere,so when you go through life struggles,dont
complain,dont grumble everybody else ,stay positive,work harder than
everybody else ,put yourself the position on succeed
you are the only one.
本文讨论了如何通过编程解决特定字符串匹配与替换的问题,包括预处理字符串以优化匹配过程,以及如何高效地执行替换操作。文章还提供了一个具体的代码示例,展示了如何实现这一任务。
2094

被折叠的 条评论
为什么被折叠?



