1 second
256 megabytes
standard input
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.
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.
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.
0001
1011
0011
000
111
impossible
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
题意:给你两个长度相同的01串s,t 找到一个新的01串p
使得p与s对应位置 字符不同的数量 等于 p与t对应位置 字符不同 的数量
不存在则输出impossible
题解:遍历一遍统计s,t对应位置字符不同的数量jishu 并标记位置
如果jishu是奇数 则输出impossible 否则 取s串 对于标记的位置 取反jishu/2个位置的值
输出
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
char a[];
char b[];
int mp[];
int main()
{
memset(mp,,sizeof(mp));
scanf("%s",a);
scanf("%s",b);
int len=strlen(a);
int jishu=;
for(int i=;i<len;i++)
{
if(a[i]!=b[i])
{ jishu++;
mp[i]=;
}
}
if(jishu%)
{
printf("impossible\n");
return ;
}
jishu/=;
for(int i=;i<len;i++)
{
if(jishu)
{
if(mp[i])
{
if(a[i]=='')
printf("");
else
printf("");
jishu--;
}
else
printf("%c",a[i]);
}
else
printf("%c",a[i]);
}
return ;
}