• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #224 Div2 A

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

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
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <stack>
 6 #include <queue>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define maxn 1000005
12 int n, m;
13 char s1[maxn],s2[maxn];
14 int main(){
15     scanf("%s%s", s1, s2);
16     int t;
17     n = strlen(s1);
18     m = strlen(s2);
19     for (int i = 0; i < n; i++){
20         if (s1[i] == '|')t = i;
21     }
22     int x=n + m - 1;
23     int y = min(t, n - t - 1);
24     if (x % 2 != 0 || y + m < n - y - 1){ printf("Impossible\n"); return 0; }
25     int j;
26     for (j = 0; j < x / 2 - t; j++)printf("%c", s2[j]);
27     printf("%s", s1);
28     for (; j < m; j++)printf("%c", s2[j]);
29     printf("\n");
30     return 0;
31 }
View Code
posted @ 2014-01-18 02:53  HaibaraAi  阅读(105)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3