Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales
1 second
256 megabytes
standard input
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.
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|T
L
AC|TL
|ABC
XYZ
XYZ|ABC
W|T
F
Impossible
ABC|
D
Impossible
题意:有两行字符串,如何把第二行的字符串加到第一行,使“|”左右两边字符个数相等,如果不能,输出Impossible
我的代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<limits.h>
#define ll long long
using namespace std;
const int maxn=1e6+10;
char ch[maxn],c[maxn];
char a[maxn],b[maxn];
int main()
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>ch;
cin>>c;
int l1=strlen(ch);
int l2=strlen(c);
int la=0,lb=0;
for(int i=0;;i++)
{
if(ch[i]=='|') break;
a[la++]=ch[i];
}
for(int i=la+1;i<l1;i++) b[lb++]=ch[i];
int La=la,Lb=lb;
if(l2<abs(la-lb)) cout<<"Impossible\n";
else
{
if((l1-1+l2)%2)
{
cout<<"Impossible\n";
}
else if(la==lb)
{
if(l2%2) cout<<"Impossible\n";
else
{
for(int i=0;i<=(l2-1)/2;i++) cout<<c[i];
cout<<a<<"|"<<b;
for(int i=(l2-1)/2+1;i<l2;i++) cout<<c[i];
cout<<endl;
}
}
else if(la>lb)
{
if(l2==la-lb) cout<<a<<"|"<<b<<c<<endl;
else
{
for(int i=0;i<(la+lb+l2)/2-la;i++) cout<<c[i];
cout<<a<<"|"<<b;
for(int i=(la+lb+l2)/2-la;i<l2;i++) cout<<c[i];
cout<<endl;
}
}
else if(la<lb)
{
if(l2==lb-la) cout<<a<<c<<"|"<<b<<endl;
else
{
for(int i=0;i<(l1-1+l2)/2-la;i++) cout<<c[i];
cout<<a<<"|"<<b;
for(int i=(l1-1+l2)/2-la;i<l2;i++) cout<<c[i];
cout<<endl;
}
}
}
return 0;
}
帆神的代码:
#include<stdio.h>
#include<string.h>
char a[1006],b[1006];
int main()
{
scanf("%s",a);
scanf("%s",b);
int la=strlen(a),lb=strlen(b);
int u;
for(int i=0;i<la;i++)
{
if(a[i]=='|')
u=i;
}
int x=u,y=la-u-1;//x—前半部分字符串的长度,y—后半部分字符串的长度
if(x>y&&lb>=x-y&&lb%2==(x-y)%2)
{
int p=(lb-x+y)/2;
for(int i=0;i<u;i++)
printf("%c",a[i]);
for(int i=0;i<p;i++)
printf("%c",b[i]);
printf("|");
for(int i=p;i<lb;i++)
printf("%c",b[i]);
for(int i=u+1;i<la;i++)
printf("%c",a[i]);
printf("\n");
}
else if(y>x&&lb>=y-x&&lb%2==(y-x)%2)
{
int p=(lb+x-y)/2;
for(int i=0;i<u;i++)
printf("%c",a[i]);
for(int i=p;i<lb;i++)
printf("%c",b[i]);
printf("|");
for(int i=u+1;i<la;i++)
printf("%c",a[i]);
for(int i=0;i<p;i++)
printf("%c",b[i]);
printf("\n");
}
else if(x==y&&lb%2==0)
{
int p=(lb+x-y)/2;
for(int i=0;i<u;i++)
printf("%c",a[i]);
for(int i=p;i<lb;i++)
printf("%c",b[i]);
printf("|");
for(int i=u+1;i<la;i++)
printf("%c",a[i]);
for(int i=0;i<p;i++)
printf("%c",b[i]);
printf("\n");
}
else
printf("Impossible\n");
return 0;
}
Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales的更多相关文章
- Codeforces Round #224 (Div. 2)
题目:http://codeforces.com/contest/382 A Ksenia and Pan Scales 一个求天平是否能够平衡的题目...水题,注意一下结果的输出就行. #inclu ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- eclipse开发go语言入门案例
1.配置eclipse下配置GO语言的插件 点击eclipse的“Help”菜单,找到“Install New Software…”菜单项.如下图: 点击“Install New Software…” ...
- vue.js循环for(列表渲染)详解
vue.js循环for(列表渲染)详解 一.总结 一句话总结: v-for <ul id="example-1"> <li v-for="item in ...
- php--------http 状态代码及其原因
HTTP 400 - 请求无效HTTP 401.1 - 未授权:登录失败HTTP 401.2 - 未授权:服务器配置问题导致登录失败HTTP 401.3 - ACL 禁止访问资源HTTP 401.4 ...
- Confluence 6 的 Crowd 设置
名字(Name) 输入一个有意义的服务器名字,会让你在 Crowd 服务器中更好的识别你的目录服务器: Crowd Server Example Company Crowd 服务器URL(Server ...
- Pollywog CodeForces - 917C (状压)
链接 大意: 一共n个格子, 初始$x$只蝌蚪在前$x$个格子, 每次最左侧的蝌蚪向前跳, 跳跃距离在范围[1,k], 并且每只蝌蚪跳跃都有一定花费, 有$q$个格子上有石头, 若有蝌蚪跳到某块石头上 ...
- UVA-10061 How many zero's and how many digits ? (数论)
题目大意:让求n!在base进制下的位数以及末尾0的连续个数. 题目分析:一个m位的b进制数N,最小是b^(m-1),最大不超过b^m,即b^(m-1)≤N<b^m.解不等式,得log10(N) ...
- Oracle11g温习-第六章:控制文件
2013年4月27日 星期六 10:33 .控制文件的功能和特点 1) [定义数据库当前物理状态] 2) [维护数据的一致性] 如果控制文件中的检查点与数据文件中的一致,则说明数据一致,可以启动到 ...
- 此纳税人登记号已用于同一期间的交易方(交易方类型为 XXX 且交易方名称为 xxxx)。
When updated Supplier's tax informations , System occurs a error:'This tax registration number is al ...
- flex布局学习总结
最近项目主要是小程序,小程序里面的布局主要采用flex布局,之前对flex 布局只是稍作了解,总结下flex 布局的常用套路 容器 Flex是Flexible Box的缩写,意为"弹性布局& ...
- Sql Server约束的学习一(主键约束、外键约束、唯一约束)
一.约束的分类 1.实体约束 实体约束是关于行的,比如某一行出现的值不允许出现在其他行,例如主键约束. 2.域约束 域约束是关于列的,对于所有行,某一列有那些约束,例如检查约束. 3.参照完整性约束 ...