Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales
来源:互联网 发布:三维插值算法 编辑:程序博客网 时间:2024/06/08 05:45
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
————————————————————————————————————————————————————————
题目大意:
第一行的字符串相当于天平,' | ' 将字符串分成左右两边,相当于天平的两边,左边两边的重量是字符的个数
第二行的字符串相当于一个个砝码
题目要求:把所有的砝码都放到天平上,判断天平能否平衡,能的话输出使它平衡的一种情况,否则输出Impossble
#include<bits/stdc++.h>#define M 100000using 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
- Codeforces Round #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 224 div.2 A. Ksenia and Pan Scales
- A. Ksenia and Pan Scales
- A. Ksenia and Pan Scales
- A. Ksenia and Pan Scales
- codeforces--2014/1/18--A. Ksenia and Pan Scales
- Codeforces 382A Ksenia and Pan Scales(水题)
- Ksenia and Pan Scales
- CF——A. Ksenia and Pan Scales
- Codeforces Round #224 (Div. 2) D. Ksenia and Pawns
- Codeforces Round #224 (Div. 2) E.Ksenia and Combinatorics
- CF224A题Ksenia and Pan Scales
- C. Vanya and Scales(Codeforces Round #308 (Div. 2))
- Codeforces Round #308 (Div. 2) C. Vanya and Scales
- Codeforces Round #308 (Div. 2) C.Vanya and Scales
- Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs
- 学车心得
- hdu2025 查找最大元素
- Install EGIT via eclipse marketplace
- HDU-#2066 一个人的旅行(Floyd & Dijkstra)
- zoj2412 hdu1198
- Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales
- TCP/IP,http,socket,长连接,短连接——小结。
- hrbust1164, 1287_____hrbust上的简单哈希
- Road Construction+求双联通分量、割点、桥+POJ
- 随机抽样一致(Random Sample Consensus, RANSAC)
- 蛇形矩阵
- LeetCode Search in Rotated Sorted Array II
- 使用存储过程
- git rebase 使用