周赛-Equidistant String 分类: 比赛 2015-08-08 15:44 6人阅读 评论(0) 收藏
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn’t equal to ti.
As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.
It’s time for Susie to go to bed, help her find such string p or state that it is impossible.
Input
The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Output
Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line “impossible” (without the quotes).
If there are multiple possible answers, print any of them.
Sample test(s)
Input
0001
1011
Output
0011
Input
000
111
Output
impossible
Note
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
判断字符不同的个数
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-9
#define LL long long
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CRR fclose(stdin)
#define CWW fclose(stdout)
#define RR freopen("input.txt","r",stdin)
#pragma comment(linker,"/STACK:102400000")
#define WW freopen("output.txt","w",stdout)
const int Max = 1e5;
char s[Max*10];
char t[Max*10];
char p[Max*10];
int num;
int main()
{
int len;
scanf("%s",s);
scanf("%s",t);
len=strlen(s);
num=0;
for(int i=0;i<len;i++)
{
if(s[i]==t[i])
{
p[i]=s[i];
}
if(s[i]!=t[i])
{
num++;
if(num&1)
{
p[i]=s[i];
}
else
{
p[i]=t[i];
}
}
}
if(num==0)
{
printf("%s",s);
}
else if(num&1)
{
printf("impossible\n");
}
else
{
p[len]='\0';
printf("%s\n",p);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
周赛-Equidistant String 分类: 比赛 2015-08-08 15:44 6人阅读 评论(0) 收藏的更多相关文章
- Find The Multiple 分类: 搜索 POJ 2015-08-09 15:19 3人阅读 评论(0) 收藏
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21851 Accepted: 8984 Sp ...
- Ultra-QuickSort 分类: POJ 排序 2015-08-03 15:39 2人阅读 评论(0) 收藏
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 48111 Accepted: 17549 ...
- Drainage Ditches 分类: POJ 图论 2015-07-29 15:01 7人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62016 Accepted: 23808 De ...
- Injector Job深入分析 分类: H3_NUTCH 2015-03-10 15:44 334人阅读 评论(0) 收藏
Injector Job的主要功能是根据crawlId在hbase中创建一个表,将将文本中的seed注入表中. (一)命令执行 1.运行命令 [jediael@master local]$ bin/n ...
- Windows7下QT5开发环境搭建 分类: QT开发 2015-03-09 23:44 65人阅读 评论(0) 收藏
Windows7下QT开法环境常见搭配方法有两种. 第一种是:QT Creator+QT SDK: 第二种是:VS+qt-vs-addin+QT SDK: 以上两种均可,所需文件见QT社区,QT下载地 ...
- cf 61E. Enemy is weak 树状数组求逆序数(WA) 分类: Brush Mode 2014-10-19 15:16 104人阅读 评论(0) 收藏
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...
- max_flow(Dinic) 分类: ACM TYPE 2014-09-02 15:42 94人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include<queue> #in ...
- SQL 分组 加列 加自编号 自编号限定 分类: SQL Server 2014-11-25 15:41 283人阅读 评论(0) 收藏
说明: (1)日期以年月形式显示:convert(varchar(7),字段名,120) , (2)加一列 (3)自编号: row_number() over(order by 字段名 desc) a ...
- SQL 按月统计(两种方式) 分类: SQL Server 2014-08-04 15:36 154人阅读 评论(0) 收藏
(1)Convert 函数 select Convert ( VARCHAR(7),ComeDate,120) as Date ,Count(In_code) as 单数,Sum(SumTrueNum ...
随机推荐
- iOS6:在你的企业系统中支持Passbook
前言 这是一篇翻译,感谢Jonathan Tang. 原文地址:iOS 6 Tutorial: Supporting Passbook within Your Enterprise Systems 正 ...
- SQL 启动服务方法
(1)windows开始菜单->Microsoft SQL Server 2012->配置工具->配置管理器
- 解决Xamarin 生成时出现 “aapt.exe”已退出,代码为 1。错误问题
项目中添加的资源或项目文件的名称不能包含 空格 横线 特殊符号 或者 Android关键字 等
- WEB简单数据操作练习
主要学习代码: Login.aspx: <!--第一种方式--> <%-- <script type="text/javascript"> funct ...
- [原创]java WEB学习笔记90:Hibernate学习之路-- -HQL检索方式,分页查询,命名查询语句,投影查询,报表查询
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- SQL封装、多态与重载
面向对象1.类:众多对象抽象出来的2.对象:类实例化出来的 3.类的定义关键字 class 4.类里面包含成员变量成员属性 成员方法 5.面向对象三大特性(1)封装目的:保护类,让类更加安全.做法:让 ...
- C++之路进阶——bzoj1030(文本生成器)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...
- 从一简单程序看C语言内存分配
int main13(){ char buf[20]="aaaa"; char buf2[] = "bbbb"; char *p1 = "111111 ...
- php CI框架目录结构及运行机制
CI目录结构 CI主要组成部分为,application(应用文件夹).system(系统文件夹)和index.php入口文件. 应用文件夹中主要是存放控制器.模型和视图等,系统文件夹中主 ...
- sql where 1=1
这段代码应该是由程序(例如Java)中生成的,where条件中 = 之后的条件是通过 if 块动态变化的.例如: String sql="select * from table_name w ...