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 的文档.本文档分成几个部分,我推荐您先读 < 安装 >,然后读< 快速上手 >.< 教程 > 比快速上手文档更详 ...
随机推荐
- Java数组数据类型
Java数组数据类型 数组是多个相同类型的数据的组合,数组中的元素可以是任何类型的数据: 一维数组 package com.ahabest.array; public class ArratTest ...
- win10安装mysql 8.0.11
mysql安装包可到官网下载,地址:https://dev.mysql.com/downloads/mysql 1.首先解压文件包,我这解压到E:\install_work\mysql目录下: 2.发 ...
- react typescript 子组件调用父组件
//父组件 import * as React from 'react'import { Input } from 'antd'const Search = Input.Searchimport &q ...
- 【Codeforces 522A】Reposts
[链接] 我是链接,点我呀:) [题意] 有人转载官方号的动态. 又有其他人转载其他人转载的动态. 问你最长的一条转载动态的链有多长. [题解] 用map把每个人的英文都转成小写的 然后从map中获取 ...
- 【1657: [蓝桥杯][算法训练VIP]】统计单词个数
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dp[i][j]表示前i个字符分成j个部分的最多匹配单词个数. 则dp[i][j] = dp[prei][j-1] + get_num(pr ...
- CODEVS2144 砝码称重2 (哈希表)
由于m很大,所以不能使用DP. 注意到n≤30,直接暴力2^n会TLE. 所以,将砝码平均分成两份,对一份进行一次暴力,用哈希表存下可能的结果. 对下一份再进行一次暴力,在哈希表中搜索剩余的砝码重量是 ...
- 子序列 NYOJ (尺取法+队列+hash) (尺取法+离散化)
子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...
- Train Problem II HDU 1023 卡特兰数
Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...
- 洛谷——P1034 矩形覆盖
https://www.luogu.org/problem/show?pid=1034 题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的 ...
- SQL SERVER 体系结构图
http://www.cnblogs.com/woodytu/p/4471386.html