codeforces--2014/1/18--A. Ksenia and Pan Scales
来源:互联网 发布:夏洛克妹妹欧洛丝 知乎 编辑:程序博客网 时间:2024/05/21 17:42
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.
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.
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.
AC|TL
AC|TL
|ABCXYZ
XYZ|ABC
W|TF
Impossible
ABC|D
Impossible#include <stdio.h>#include <string.h>int main(){ int l = 0 , r = 0 , ll , i , sum ; char str1[100] , str2[100] ; scanf("%s%s", str1,str2); l = strlen(str1); for(i = 0 ; str1[i] != '\0' ; i++) if(str1[i]=='|') break; r = l - i - 1; l = i ; ll = strlen(str2); if(r - l > ll || l - r > ll || (l + r + ll)%2==1) printf("Impossible\n"); else { sum = (l+r+ll)/2; for(i = 0 ; i < (sum - l) ; i++) printf("%c", str2[i]); for(i = 0 ; i < l ; i++) printf("%c", str1[i]); printf("|"); for(i = l + 1 ; str1[i] != '\0' ; i++) printf("%c", str1[i]); for(i = sum-l ; str2[i] != '\0' ; i++) printf("%c", str2[i]); printf("\n"); } return 0;}
- codeforces--2014/1/18--A. Ksenia and Pan Scales
- A. Ksenia and Pan Scales
- A. Ksenia and Pan Scales
- A. Ksenia and Pan Scales
- codeforces 224 div.2 A. Ksenia and Pan Scales
- Codeforces Round #224 (Div. 2)A. Ksenia and Pan Scales
- Codeforces Round #224 (Div. 2) A - Ksenia and Pan Scales
- Codeforces 382A Ksenia and Pan Scales(水题)
- Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales
- Ksenia and Pan Scales
- CF——A. Ksenia and Pan Scales
- CF224A题Ksenia and Pan Scales
- CodeForces 382D Ksenia and Pawns
- CodeForces 382D Ksenia and Pawns __DFS
- Codeforces #308 C. Vanya and Scales
- Codeforces 552C Vanya and Scales
- codeforces 552 C Vanya and Scales
- [CodeForces 552C]Vanya and Scales[math]
- AChartEngine应用之LineChart(模拟三角函数sin,cos)
- hdfs 数据一致性
- 什么是内存泄露
- 【经典例题】高次幂的后几位数
- LeeCode 边界条件注意
- codeforces--2014/1/18--A. Ksenia and Pan Scales
- 教你怎么修改通讯录短信默认头像
- linux设置开机服务自动启动
- Given an array of integers, every element appears twice except for one. Find that single one.
- ahhfah,大上午的,烦人
- 用.htaccess实现301转向
- 如何通过预加载器提升网页加载速度
- Ipad Video Lessons
- Web版Telnet工具设计与实现