Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】
2 seconds
256 megabytes
standard input
standard output
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
The first line contains a non-empty string s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.
Print the new sum that Xenia can count.
3+2+1
1+2+3
1+1+3+1+3
1+1+1+3+3
2
2
【代码】:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; const int N=100005;
int k;
char s[110];
int a[110]; int main()
{
scanf("%s",s);
for(int i=0;i<strlen(s);i+=2)//+=2
{
a[k++]=s[i]-'0';
}
sort(a,a+k); printf("%d",a[0]);//第一个前面无+,单独输出
for(int i=1;i<k;i++)
printf("+%d",a[i]);
printf("\n");
}
Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】的更多相关文章
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)
A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...
- Codeforces Round #197 (Div. 2)
A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...
- Codeforces Round #197 (Div. 2) : E
看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...
- [置顶] Codeforces Round #197 (Div. 2)(完全)
http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...
- Codeforces Round #287 (Div. 2) D. The Maths Lecture [数位dp]
传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #197 (Div. 2) C,D两题
开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...
- Codeforces Round #197 (Div. 2) : C
哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...
- Codeforces Round #197 (Div. 2) : D
这题也是一个线段树的水题: 不过开始题目没看明白,害得我敲了一个好复杂的程序.蛋疼啊.... 最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去... 以后比赛的时候不喝啤酒了,再也 ...
随机推荐
- VNC 4.25注册码
注册码:ELBMU-ZFYMV-2HC77-73M46-UL4TA97KLJ-VBTAL-T7GN2-K29PS-ANXCA45YV6-WXWMJ-NPAAV-HWD7Q-W5HVAL76HR-642 ...
- Codeforces 442B. Andrey and Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 跟我一起了解koa之koa的cookie(三)
代码中写入 然后我们每次刷新浏览器,代码里面的pvid都会改变 我们可以读取cookie 访问json数据出现结果
- 细说WPF自定义路由事件
WPF中的路由事件 as U know,和以前Windows消息事件区别不再多讲,这篇博文中,将首先回顾下WPF内置的路由事件的用法,然后在此基础上自定义一个路由事件. 1.WPF内置路由事件 W ...
- Kafka在window上安装部署
1.准备工作 ①jdk 具体自行百度安装jdk,配置好 JAVA_HOME和path, 下载地址: http://www.oracle.com/technetwork/java/javase/ ...
- SSH协议的Python实现paramiko
目录 paramiko安装 SSHClient类与SFTPClient类 SSHClient类的方法 SFTPClient类的方法 paramiko的基本使用 paramiko.SSHClient两种 ...
- day19 作业
今日作业 1.什么是对象?什么是类? 对象:特征和技能的结合体 类:一系列对象 相同的特征和技能的结合体 2.绑定方法的有什么特点 对象调用类内部的函数 称之为绑定方法,特点: 不同的对象调用该绑定方 ...
- linux平台进行c语言源码安装
安装c源程序的步骤: 1. ./configure --prefix 执行编译检测 指定安装路径 2. make 编译 3. sudo make install 编译后安装 前两步可以合成一步(mak ...
- mysql高级教程(一)-----逻辑架构、查询流程、索引
mysql逻辑架构 和其它数据库相比,MySQL有点与众不同,它的架构可以在多种不同场景中应用并发挥良好作用.主要体现在存储引擎的架构上,插件式的存储引擎架构将查询处理和其它的系统任务以及数据的存储提 ...
- Eclipse使用过程的常见问题:
3-1 "Failed to load the JNI shared library" -jdk 与eclipse位数不一致出现的问题 解决方法: ...