CodeForces 382A Ksenia and Pan Scales

原创 2018年04月16日 16:01:57

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.(如果一次输入有多种结果,输出其中一种就行)

Examples
input
AC|T
L
output
AC|TL
input
|ABC
XYZ
output
XYZ|ABC
input
W|T
F
output
Impossible
input
ABC|
D
output
Impossible
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
	int i,j,k;
	char a[30],b[30];
	int n,m,t;
	int l1,l2;
	int la,lb;
	gets(a);
	gets(b);
	la=strlen(a);
	lb=strlen(b);
	for(i=0;i<la;i++)
	{
		if(a[i]=='|')
		{
			t=i;
			break;
		}
	}
	l1=t;
	l2=la-t-1;
	if(l1==l2)
    {
    	if(lb&1)
        {
        	cout<<"Impossible"<<endl;
		}
		else
		{
			for(i=0;i<lb/2;i++)
			{
				cout<<b[i];
			}
			for(i=0;i<l1;i++)
			{
				cout<<a[i];
			}
			cout<<'|';
			for(i=t+1;i<la;i++)
			{
				cout<<a[i];
			}
			for(i=lb/2;i<lb;i++)
			{
				//cout<<b[i]<<endl;
				cout<<b[i];
			}
			cout<<endl;
		}
	}
	else
	{
		if(l1>l2)
		{
			n=l1-l2;
			m=lb-n;
			//if(m&1)这是第一次提交时错误的原因,如果当给的重量不够补的时候,m的结果小于0,这就不能够准确判断m是奇数还是偶数了 
			if(m&1||m<0)
			{
				cout<<"Impossible"<<endl;
			}
			else
			{
				for(i=n+m/2;i<lb;i++)
				{
					cout<<b[i];
				}
				for(i=0;i<l1;i++)
				{
					cout<<a[i];
				}
				cout<<'|';
				for(i=t+1;i<la;i++)
				{
					cout<<a[i];
				}
				for(i=0;i<n+m/2;i++)
				{
					//cout<<b[i]<<endl;这里是第二次提交时错误的原因,如果天平右边有多个b[i]要输出,那么回车就多余了,错误原因是样例误导了我 
					cout<<b[i];
				}
				cout<<endl;
			}
		}
		else
	    {
	    	n=l2-l1;
			m=lb-n;
			//if(m&1)这是第一次提交时错误的原因,如果当给的重量不够补的时候,m的结果小于0,这就不能够准确判断m是奇数还是偶数了
			if(m&1||m<0)
			{
				cout<<"Impossible"<<endl;
			}
			else
			{
				for(i=0;i<n+m/2;i++)
				{
					cout<<b[i];
				}
				for(i=0;i<l1;i++)
				{
					cout<<a[i];
				}
				cout<<'|';
				for(i=t+1;i<la;i++)
				{
					cout<<a[i];
				}
				for(i=n+m/2;i<lb;i++)
				{
					//cout<<b[i]<<endl;这里是第二次提交时错误的原因,如果天平右边有多个b[i]要输出,那么回车就多余了,错误原因是样例误导了我 
					cout<<b[i];
				}
				cout<<endl;
			}
		}
	}
	return 0;
}

Codeforces 382A Ksenia and Pan Scales(水题)

题目链接:Codeforces 382A Ksenia and Pan Scales 题目大意:判断两边是否可以拥有相同的字母数,每个字母z...
  • u011328934
  • u011328934
  • 2014-02-01 17:32:48
  • 992

A. Ksenia and Pan Scales

A. Ksenia and Pan Scales time limit per test 1 second memory limit per test 256 megabytes inpu...
  • u013022160
  • u013022160
  • 2014-01-18 01:06:31
  • 966

codeforces 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 ...
  • u013082590
  • u013082590
  • 2014-01-18 08:58:05
  • 718

CF224A题Ksenia and Pan Scales

不解释。。。 Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia ha...
  • u013013910
  • u013013910
  • 2014-01-18 19:14:48
  • 922

CF——A. Ksenia and Pan Scales

Input The first line has a non-empty sequence of characters describing the scales. In this sequen...
  • u011470356
  • u011470356
  • 2014-04-09 19:02:25
  • 481

Ksenia and Pan Scales(思维题)

题目链接:http://codeforces.com/contest/382/problem/A简要说明题目:输入一个字符串,并且含有字符“|”一个(除此之外输入只含有大写字母),表示分隔线,在分割线...
  • KK_2018
  • KK_2018
  • 2018-04-14 20:34:30
  • 0

codeforces--2014/1/18--A. Ksenia and Pan Scales

A. Ksenia and Pan Scales time limit per test 1 second memory limit per test 256 megabytes ...
  • u013015642
  • u013015642
  • 2014-01-18 08:13:40
  • 937

Codeforces 552.C Vanya and Scales

7.10.D 思维 进制转换
  • qq_26071477
  • qq_26071477
  • 2016-07-10 20:34:07
  • 393

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 megabyte...
  • u010160562
  • u010160562
  • 2014-01-18 10:43:28
  • 944
收藏助手
不良信息举报
您举报文章:CodeForces 382A Ksenia and Pan Scales
举报原因:
原因补充:

(最多只允许输入30个字)