Codeforces Round #303 (Div. 2) B
来源:互联网 发布:海文网络计划软件教程 编辑:程序博客网 时间:2024/05/29 09:13
题意:已知2个字符串s,t。要求输出一个字符串p,其距离和s,t均相等。距离定义: 若s[1]=1,p[1]=0 距离+=abs(1-0)。
思路:确定s,t中,不同字符的个数,如果是偶数才可以进行,再对半分
错误点: strlen不要放在for循环里啊。 死循环tmd!
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e5+50;char s1[maxn],s2[maxn];int main(void){ scanf("%s",s1+1); scanf("%s",s2+1); int cnt=0; int len=strlen(s1+1); for(int i=1; i<=len; i++) { if(s1[i]!=s2[i]) cnt++; } //cout << "cnt=" << cnt << endl; if(cnt%2==1) { printf("impossible\n"); return 0; } else { int a=0; for(int i=1; i<=len ; i++) { if(s1[i]!=s2[i]) { a++; if(a<=cnt/2) printf("%c",s1[i]); else printf("%c",s2[i]); } else printf("%c",s1[i]); } } puts("");}
阅读全文
0 0
- Codeforces Round #303 (Div. 2) B
- Codeforces Round #303 (Div. 2) A,B,D题解
- Codeforces Round #303 (Div. 2) A B C D
- Codeforces Round #303 (Div. 2)(A,B,C,D)
- Codeforces Round #303 (Div.2)-B. Equidistant String(模拟)
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #206 (Div. 2) - b
- Codeforces Round #202 (Div. 2)B-贪心
- hdu1054 Strategic Game
- Connection接口中isClosed() 和 isValid() 的区别
- POJ
- 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5
- Xamarin.Forms 多屏显示深度解析
- Codeforces Round #303 (Div. 2) B
- 2017/8/7 离线赛
- myeclipse中svn突然失效问题
- 用memset清空数组时要注意的问题
- Android获取手机存储状态
- 日常篇
- AOP通知类型
- F
- 递归 汉诺塔问题