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

时间:2024-01-16 11:10:14

B. Equidistant String

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/545/problem/B

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

0001
1011

Sample Output

0011

HINT

题意

给你两串只含01的字符串,然后让你构造出一组字符串,让他们的和构造出来的字符串差异都相同

题解:

首先看这两组有多少个位置不一样,如果是奇数,直接输出不可能,如果是偶数,那么就前一半为s,后一半为t就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s;
string t;
int main()
{ cin>>s>>t;
int flag=;
int n=s.size();
if(s==t)
{
cout<<s<<endl;
return ;
}
for(int i=;i<n;i++)
{
if(s[i]!=t[i])
flag++;
}
if(flag%==)
{
printf("impossible\n");
}
else
{
flag/=;
for(int i=;i<n;i++)
{
if(s[i]!=t[i])
{
if(flag>)
{
cout<<s[i];
flag--;
}
else
cout<<t[i];
}
else
cout<<s[i];
}
}
}