B - Equidistant String

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 Input

Input
0001
1011
Output
0011
Input
000
111
Output
impossible

Hint

In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.

题意:

给定两条长度相等的字符串s和t,字符串之间的距离为两串相同位置不相等元素的个数,问能否得到一个长度与两串相同的字符串p使得p的距离离s,t相等,若有遍输出p。

水啊!s和t的距离ans为偶数就可以,否则就没有。输出的话只要将s的前ans/2个不同的元素转换为与t相同即可得字符串p。

附AC代码:

#include<iostream>
#include<cstring>
using namespace std; string s,t,p; int main(){
cin>>s;
cin>>t;
int ans=;
p=s;
int len=s.size();
for(int i=;i<len;i++){
if(s[i]!=t[i]){
ans++;
t[i]=' ';
}
}
int temp=ans/;
if(ans%==){
for(int i=;i<len;i++){
if(t[i]==' '&&temp){
if(p[i]=='')
p[i]='';
else
p[i]='';
temp--;
}
}
for(int i=;i<len;i++){
cout<<p[i];
}
}
else{
cout<<"impossible";
}
return ;
}

B - Equidistant String的更多相关文章

  1. Codeforces Round #303 (Div. 2) B. Equidistant String 水题

    B. Equidistant String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...

  2. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  3. 周赛-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 standar ...

  4. 545B. Equidistant String

    题目链接 输入两个只含有01的字符串,s,t 求一个字符串p使到s,t的距离一样 这里的距离是指对应位置:0-0的距离是0 ,o-1的距离是1 ,1-1的距离是0,1-0的距离是1 这里只要求找出满足 ...

  5. Codeforces Round #303 (Div. 2) B 水 贪心

    B. Equidistant String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. Codeforces Round #303 (Div. 2)

    A.Toy Cars 题意:给出n辆玩具车两两碰撞的结果,找出没有翻车过的玩具车. 思路:简单题.遍历即可. #include<iostream> #include<cstdio&g ...

  7. Educational Codeforces Round 121 (Rated for Div. 2)——A - Equidistant Letters

    A - Equidistant Letters 题源:https://codeforces.com/contest/1626/problem/A 今天上午VP了这场CF,很遗憾的是一道题也没写出来,原 ...

  8. 透过WinDBG的视角看String

    摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...

  9. JavaScript String对象

    本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...

随机推荐

  1. 小胖学PHP总结4-----PHP的字符串操作

    1.字符串连接 字符串是通过半角句号"."来连接的.能够把两个或两个以上的字符串连接成一个字符串. 2.去除字符串首尾空格和特殊字符 PHP中提供了trim()函数去除字符串左右两 ...

  2. 笔记04 WPF对象引用

    转自:http://www.fx114.net/qa-261-90254.aspx 我们应该都知道,XAML是一种声明式语言,XAML的标签声明的就是对象.一个XAML标签会对应着一个对象,这个对象一 ...

  3. vs2010中添加dll文件

    1.更改设置 1.1   project->properties->configuration properties->C/C++->General->Addtional ...

  4. CUGBACM_Summer_Tranning1 二进制枚举+模拟+离散化

    整体感觉:这个组队赛收获还挺多的.自从期末考试以后已经有一个多月没有 做过组队赛了吧,可是这暑假第一次组队赛就找回了曾经的感觉.还挺不错的!继续努力!! 改进的地方:这次组队赛開始的时候题目比較难读懂 ...

  5. .Net Core表单验证

    验证 attributes: Attributes Input Type [EmailAddress] type=”email” [Url] type=”url” [HiddenInput] type ...

  6. HashSet、LinkHashSet、TreeSet总结

    HashSet:散列集,集合中的元素不允许重复,但是不要求顺序,输出的顺序和进入HashSet的顺序是没有关系的 LinkedHashSet :链表散列集,集合中的元素不允许重复,同时要求和进入Set ...

  7. HDU 4622 Reincarnation 后缀自动机 // BKDRHash(最优hash)

    Reincarnation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) P ...

  8. g++: command not found的解决

    G++没有装或却没有更新   以下方法都可以试试: centos: yum -y update gcc yum -y install gcc+ gcc-c++   ubuntu: apt-get up ...

  9. 九度OJ 1094:String Matching(字符串匹配) (计数)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1259 解决:686 题目描述: Finding all occurrences of a pattern in a text is a p ...

  10. Chef vs Puppet vs Ansible vs Saltstack: Which Works Best For You?

    Ansible vs SaltStack 谁才是自动化运维好帮手? - CSDN博客 https://blog.csdn.net/a105421548/article/details/53558598 ...