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 input

output

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.

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 s is 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

【代码】:

#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");
}

  

时间: 2024-10-09 04:07:25

Codeforces Round #197 (Div. 2) A. Helpful Maths【字符串/给一个连加计算式,只包含数字 1、2、3,要求重新排序,使得连加的数字从小到大】的相关文章

线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

题目传送门 1 /* 2 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 3 详细解释:http://www.xuebuyuan.com/1154895.html 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 #include <string> 10 #include <c

Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 #include <iostream> #include <cstdio> #include <cstring> #include <stdlib.h> #include <algorithm> #include <cmath> usi

#197 (div.2) A. Helpful Maths

1.题目描述:点击打开链接 2.解题思路:抽取出所有的数字,排序后输出即可. 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #include<vector> #include<stack> #include<map

Codeforces Round #166 (Div. 2)---D. Good Substrings(字符串)

You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad. A substring s[l-r] (1?≤?l?≤?r?≤?|s|) of string s??=??s1s2-s|s| (where |s| is the length of string s) is string ?slsl?+?1-sr. The substri

Codeforces Round #313 (Div. 2) D.Equivalent Strings (字符串)

感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #include <iostream> #include <cstring> #define clr(x,c) memset(x,c,sizeof(x)) using namespace std; const int N = 200005; char s[N], t[N]; int sc[30],

Codeforces Round #536 (Div. 2)

目录 Codeforces Round #536 (Div. 2) A 题目大意 题解 卡点 C++ Code: B 题目大意 题解 卡点 C++ Code: C 题目大意 题解 卡点 C++ Code: D 题目大意 题解 卡点 C++ Code: E 题目大意 题解 卡点 C++ Code: F 题目大意 题解 卡点 C++ Code: Codeforces Round #536 (Div. 2) A 题目大意 给你一个\(n\times n(n\leqslant500)\)的矩阵,只包含.

Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环节)

题目链接:http://codeforces.com/problemset/problem/456/B B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fedya studies in a gymnasium. Fedya's maths hometask is to calculate t

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #260 (Div. 2)

A. Laptops 题目意思: 给定n台电脑,第i台电脑的价格是ai ,质量是bi ,问是否存在一台电脑价格比某台电脑价格底,但质量确比某台电脑的质量高,即是否存在ai < aj 且 bi > bj ? 解题思路: 这题一定要看题目,a都是1~n的不同数,b也是1~n的不同数,此题只需要判断ai 是否等于bi ,如果ai != bi 的话,则输出“Happy Alex”,如果所有的ai  == bi 则输出“Poor Alex” 证明:先将a按照从小到大排序,当i<j时ai <