A. Helpful Maths
来源:互联网 发布:淘宝buy 视频 编辑:程序博客网 时间:2024/05/16 16:02
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<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;int main(){char a[100];char temp;int i ;int j;scanf("%s",a); for(i = 0; (a[i] != '\0') && (a[i+1] != '\0'); i= i+2){for(j= 0; (a[j] != '\0') && (a[j+1] != '\0'); j= j+2){if(a[j] > a[j+2]){temp =a[j];a[j] = a[j+2];a[j+2] =temp;}}}printf("%s\n",a);return 0;}
- A. Helpful Maths
- A. Helpful Maths
- 339A - Helpful Maths
- 【CodeForces】A. Helpful Maths
- CF197#DIV2:A-Helpful Maths
- CodeForces 339A Helpful Maths
- CodeForces-339A-Helpful Maths
- CF 339A Helpful Maths
- codeforces 339A Helpful Maths
- Problem--339A--Codeforces-- A. Helpful Maths
- Helpful Maths
- Helpful Maths
- Helpful Maths
- #197 (div.2) A. Helpful Maths
- CodeForces 339 A.Helpful Maths(水~)
- codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题
- Codeforces Round #197 (Div. 2) A. Helpful Maths
- Codeforces Round #197 (Div. 2)A. Helpful Maths
- 【C++基础之八】函数指针和回调函数
- PHP三位创始人传奇的诞生简介
- 改善C++ 程序的150个建议学习之建议31:了解new_handler的所作所为
- linux系统下修改文件夹目录权限 .
- ORACLE PL/SQL编程之PL/SQL 流程控制语句
- A. Helpful Maths
- python User-defined Exceptions
- IOS后台执行
- JSONObject简介
- 由于nvmini.sys引起蓝屏故障的处理方法
- android开发之短信监听拦截_BroadcastReceiver的使用
- IPsec SA 创建步骤——IKE协议
- poj 2352-Stars
- Unable to load native-hadoop library 和 Snappy native library not loaded 的解决