Codeforces Helpful Maths

Codeforces Helpful Maths

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

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.

Sample test(s)
input
3+2+1

output
1+2+3

input
1+1+3+1+3

output
1+1+1+3+3

input
2

output
2

这种题目由于keyword少,所以就能够转换为counting sort的思想去解决。这样时间效率就仅仅有O(n)了。

void HelpfulMaths()
{
	int A[4] = {0};
	int a;
	while (scanf("%d", &a) != EOF)
	{
		A[a]++;
		getchar();
	}
	int total = A[1]+A[2]+A[3]-1;
	for (unsigned i = 0; i < A[1]; i++, total--)
	{
		printf("1");
		if (total) printf("+");
	}
	for (unsigned i = 0; i < A[2]; i++, total--)
	{
		printf("2");
		if (total) printf("+");;
	}
	for (unsigned i = 0; i < A[3]; i++, total--)
	{
		printf("3");
		if (total) printf("+");
	}
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117614.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 【gTest】gtest简介及简单使用

    【gTest】gtest简介及简单使用【gTest】gtest简介及简单使用gtest是一个跨平台(Liunx、MacOSX、Windows、Cygwin、WindowsCEandSymbian)的C++测试框架,有google公司发布。gtest测试框架是在不同平台上为编写C++测试而生成的。从http://code.google.com/p/googletest/downloads/detail?name=gtest-1.7.0.zip&can=2&q=下载最新的gtest-1.7.0版本在Windows下编

    2022年9月29日
    2
  • 软件测试用例编写方法_软件测试用例包括

    软件测试用例编写方法_软件测试用例包括编写测试用例HttpRunnerv3.x支持三种测试用例格式pytest,YAML和JSON。官方强烈建议以pytest格式而不是以前的YAML/JSON格式编写和维护测试用例格式关系如下图所示

    2022年7月29日
    8
  • CPLD和FPGA的区别(2)

    CPLD和FPGA的区别(2)可编程逻辑器件主要包括FPGA和CPLD,FPGA是FieldProgrammableGateArray缩写,CPLD是ComplexPromrammableLogicDevice的缩写。   从可编程逻辑器件的发展历史上来讲,CPLD一般是指采用乘积相结构的基

    2022年5月5日
    39
  • 如何判断二极管的极性_二极管的反向饱和电流

    如何判断二极管的极性_二极管的反向饱和电流三极管饱和状态的判断比如上图如何判断电路正常状态下(麦克风无声音)Q1饱和而不是Q2饱和?首先看Q1:因为R2=100R3所以电流的话R3是100倍的R2,但是8050放大系数是200倍以上,说明此时三极管已经无力再放大这个基极电流了,三极管处于饱和状态而后边Q2R3是R4的30倍左右,很明显电流的话根本就用不上HFE放大系统,处于截止状态…

    2025年10月23日
    2
  • 齐博建站指南(艾戈勒)

    齐博建站指南使用手册http://www.qibosoft.com/help/          /template/default/list_tpl1、新建风格:template/XXX  data/style 下新建XXX.php2、需要全部静态的话,需要录入php标识的头尾3、加载list模块

    2022年4月13日
    52
  • 卸载奇安信天擎,流氓软件怎么卸载_奇安信和360天擎

    卸载奇安信天擎,流氓软件怎么卸载_奇安信和360天擎奇安信天擎,很多朋友应该都不陌生,现在很多公司都要求每个员工的电脑上必须安装奇安信天擎这个软件,尤其是稍微大一点的公司,数据需要保密或容易被攻击的公司,奇安信可以有效的防御这些攻击。看到这是不是有朋友在想这不是一个很好的防御软件吗,为什么说是流氓软件呢?这个软件之所以叫它流氓软件,是因为这个软件一旦安装,既无法退出也无法卸载,有些朋友现在会想,这个软件就放那放着就好了啊,反正是防御的软件,我只能说你还没有了解奇安信的缺点。奇安信与一切杀毒软件冲突,公司要求安装奇安信,你就要把电脑之前的杀毒软件卸载,这

    2022年9月16日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号