Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales

A. Ksenia and Pan Scales
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.

The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.

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|T
L
output
AC|TL
input
|ABC
XYZ
output
XYZ|ABC
input
W|T
F
output
Impossible
input
ABC|
D
output
Impossible

————————————————————————————————————————————————————————


题目大意:

第一行的字符串相当于天平,' | '    将字符串分成左右两边,相当于天平的两边,左边两边的重量是字符的个数

第二行的字符串相当于一个个砝码

题目要求:把所有的砝码都放到天平上,判断天平能否平衡,能的话输出使它平衡的一种情况,否则输出Impossble


#include<bits/stdc++.h>
#define M 100000
using namespace std;
char s1[M],s2[M];
int main()
{

    int flag=0,ans1=0,ans2=0;
    scanf("%s",s1);
    int l1=strlen(s1);
    for(int i=0;i<l1;++i){
        if(!flag) ans1++;
        if(s1[i]=='|') flag=1;
        if(flag) ans2++;
    }
    scanf("%s",s2);
    int l2=strlen(s2);
    int tmp=(ans1+ans2+l2)/2;
    if(ans1>tmp||ans2>tmp||((ans1+ans2+l2)%2)){
        printf("Impossible\n");
    }
    else{

        for(int i=0;i<abs(ans1-tmp);++i) cout<<s2[i];
        for(int i=0;i<l1;++i) cout<<s1[i];
        for(int i=abs(ans1-tmp);i<l2;++i) cout<<s2[i];
        cout<<endl;
    }
    return 0;
}




















12313

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值