CF——A. Ksenia and Pan Scales

来源:互联网 发布:魔兽世界淘宝买金价格 编辑:程序博客网 时间:2024/06/08 10:59
Input

The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.

The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.

It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.

Output

If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.

If there are multiple answers, print any of them.

Sample test(s)
input
AC|TL
output
AC|TL
input
|ABCXYZ
output
XYZ|ABC
input
W|TF
output
Impossible
input
ABC|D
output
Impossible
#include <iostream>#include <cstring>using namespace std;int main(){    string s,str;    int i,j,k,L=0,R=0;    int vis[105];    memset(vis,-1,sizeof(vis));    cin>>s;    cin>>str;    int len=s.size(),len1=str.size();    for(i=0;i<len;i++)    {        if(s[i]=='|')        break;        L++;        vis[s[i]-'A']=0;    }    i++;    for(i;i<len;i++)    {        R++;        vis[s[i]-'A']=1;    }    for(i=0;i<len1;i++)    {        if(L<R)        {            L++;            vis[str[i]-'A']=0;        }        else        {            R++;            vis[str[i]-'A']=1;        }    }    if(L!=R)    cout<<"Impossible"<<endl;    else    {        for(i=0;i<26;i++)        {            if(vis[i]==0)            cout<<char(i+'A');        }        cout<<"|";        for(i=0;i<26;i++)        {            if(vis[i]==1)            cout<<char(i+'A');        }        cout<<endl;    }    return 0;}


0 0