B - Helpful Maths
Problem description
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.
Input
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 sis a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.
Output
Print the new sum that Xenia can count.
Examples
Input
3+2+1
Output
1+2+3
Input
1+1+3+1+3
Output
1+1+1+3+3
Input
2
Output
2
解题思路:取出原字符串中的所有数字字符到一个int数组中,排序,然后按格式输出即可,水过。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
char str[];int k=,num[];
cin>>str;
for(int i=;str[i]!='\0';++i)
if(i%==)num[k++]=str[i]-'';
sort(num,num+k);
for(int i=;i<k-;++i)
cout<<num[i]<<'+';
cout<<num[k-]<<endl;
return ;
}
B - Helpful Maths的更多相关文章
- Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】
A. Helpful Maths time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Helpful Maths
Xenia the beginner mathematician is a third year student at elementary school. She is now learning t ...
- [ An Ac a Day ^_^ ] CodeForces 339A Helpful Maths
熄灯了才想起来没写博客 赶紧水一道题碎觉…… #include<stdio.h> #include<iostream> #include<algorithm> #i ...
- codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)
题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...
- codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题
A.题意就是把字符串里面的数字按增序排列,直接上代码. #include <string.h> #include <stdio.h> #include <algorith ...
- Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)
A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...
- CodeForces Round 197 Div2
这次出的题水爆了,借着这个机会终于把CF的号变蓝了.A. Helpful Mathstime limit per test2 secondsmemory limit per test256 megab ...
- Codeforces Round #197 (Div. 2)
A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...
- 欢迎来到 Flask 的世界
欢迎来到 Flask 的世界 欢迎阅读 Flask 的文档.本文档分成几个部分,我推荐您先读 < 安装 >,然后读< 快速上手 >.< 教程 > 比快速上手文档更详 ...
随机推荐
- JS DOM节点(当前标签和同级、父级、子级..之间的关系)
1. 通过顶层document节点获取 1) document.getElementById(elementId) //根据id获得 2) document.getElementsByNa ...
- modelsim 仿真软件 百度云分享 modelsim se 10.7 10.6d 10.6c 10.5 10.4
modelsim se 10.7 链接:https://pan.baidu.com/s/1NDC2yMCZmA4bIRSk2dUiTg 提取码:4l1d 复制这段内容后打开百度网盘手机App,操作更方 ...
- Jmeter读取excel表中用例数据实现接口压测
传统的接口测试,都是在接口中手动输入不同用例准备的多种场景参数数据,一遍一遍的输入来执行多个不同的用例,但是现在利用excel表格准备各种类型的数据,使用Jmeter中Jmeter CSV Data ...
- 6.3.4 使用marshal 模块操作二进制文件
Python 标准库 marshal 也可以进行对象的序列化和反序列化,下面的代码进行了简单演示. import marshal x1 = 30 x2 = 5.0 x3 = [1,2,3] x4 = ...
- 【郑轻邀请赛 B】base64解密
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2128 [题意] [题解] 把密文; 在表中找到每个字符对应的数字; 然后转换成相应的 ...
- MINSUB - Largest Submatrix
MINSUB - Largest Submatrix no tags You are given an matrix M (consisting of nonnegative integers) a ...
- 1414 冰雕 51nod 暴力
1414 冰雕 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 白兰大学正在准备庆祝成立256周年.特别任命副校长 ...
- K - 贪心 基础
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containi ...
- [bzoj1812][IOI2006]riv_多叉树转二叉树_树形dp
riv bzoj-1812 IOI-2006 题目大意:给定一棵n个点树,要求在上面建立k个收集站.点有点权,边有边权,整棵树的代价是每个点的点权乘以它和它的最近的祖先收集站的距离积的和. 注释:$1 ...
- 实现MVC.NET 5的国际化
实现国际化有三种做法: 创建资源文件. 每种语言设置一套单独的View. 1 + 2. 通常而言,第一种方法的可维护性是最高的.因为随着项目的规模的扩大,为每种语言设置一套单独的View,前期的工作量 ...