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");
}
最新文章
- boxsizing属性 IE盒模型和标准盒模型
- String-原型属性
- NodeJs和ReactJs单元测试工具——Jest
- web.xml 的加载过程
- ActiveMQ学习(三)——MQ的通讯模式
- php单引号、双引号与数据库
- C# 多线程、结构体
- [转]C++学习心得
- hdu 5730 Shell Necklace fft+cdq分治
- Makefile条件推断 ——————————【Badboy】
- 解决ie 低版本的 background-size 兼容问题
- AP付款出现(-1)例外处理
- vfd with stm8
- SpringBoot的自动配置原理
- jmeter向ActiveMQ发送消息_广播/订阅(Topics 队列)
- python 列表 元祖
- 一个简单的C语言题背后的故事
- Ubuntu 16.04安装sogou 拼音输入法
- 自定义指令 格式化input数据为非负整数
- Oracle增加一列、修改一列数据类型