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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 内存对齐的规则以及作用[通俗易懂]

    内存对齐的规则以及作用

    2022年1月20日
    38
  • php 手机号正则_正则验证手机号是否合法

    php 手机号正则_正则验证手机号是否合法随着时代的发展,手机号码也在不断扩展。当我在进行PHP网页开发的时候,直接采用在网上找的手机号的正则表达式验证,结果后来测试的时候发现:当我使用的手机号177开头的进行输入时,竟然显示请输入正确的手机号,后来一看正则表达式是没有设定17开头的号码,于是又进行了学习,最终,得到了最新手机号的正则表达式验证(如下代码),以供自己和大家日后学习使用。//$phone存放手机号,$phoneErr存放手机号的错误信息//首先判定手机号不为空,然后进行正则表达式的手机号验证if(!empty($phone))

    2022年9月16日
    0
  • Spring Boot热部署-Spring loaded

    Spring Boot热部署-Spring loaded

    2021年5月16日
    150
  • siamfc代码解读_SiamFC算法改进思路「建议收藏」

    siamfc代码解读_SiamFC算法改进思路「建议收藏」视频追踪问题中,目标通常是连续可微的。SiamFC利用全卷积孪生网络结构对搜索域和样本图像进行相似度匹配,实现追踪目标。本文分析了SiamFC在vot2015数据集上的追踪结果,总结出以下问题,并提出针对性的改进方案。表现鲁棒小范围晃动运动模糊短时局部遮挡重点问题光照变化视频中白色猫由亮处转入阴影中,跟踪结果开始出现偏差。光照条件较差,而且目标的衣服为黑色,与背景相似。特征不够明显。形变、尺度变换…

    2022年9月28日
    1
  • winfrom – 重定向控制台的输入输出

    winfrom – 重定向控制台的输入输出

    2021年8月12日
    52
  • 内部类与静态内部类的区别_禁止序列化非静态类的内部类

    内部类与静态内部类的区别_禁止序列化非静态类的内部类&nbsp;&nbsp;&nbsp;&nbsp;如果一个类中定义了静态成员变量和静态方法,那么静态方法可以访问静态成员变量,而无法访问非静态成员变量,并且静态成员变量和静态方法是随着类的加载而加载、非静态成员变量和方法的声明周期是由对象的声明周期控制的。&nbsp;&nbsp;&nbsp;&nbsp;静态内部类和非静态内部类同静态方法和非静态方法类似。为什么要使用内部类&nbsp;&n…

    2022年10月11日
    0

发表回复

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

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