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


相关推荐

  • django的orm查询方法_django获取get请求参数

    django的orm查询方法_django获取get请求参数前言查找是数据库操作中一个非常重要的技术。查询一般就是使用filter、exclude以及get三个方法来实现。我们可以在调用这些方法的时候传递不同的参数来实现查询需求。在ORM层面,这些查询条件都

    2022年7月31日
    3
  • vue详解_vuex教程

    vue详解_vuex教程Vuex是做什么的?官方解释:Vuex是一个专为Vue.js应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化。Vuex

    2022年8月7日
    1
  • 解决IBasicVideo::GetCurrentImage返回0x8000ffff(E_UNEXPECTED Catastrophic failure)错误

    解决IBasicVideo::GetCurrentImage返回0x8000ffff(E_UNEXPECTED Catastrophic failure)错误经过查阅一番资料后,得到如下的解决方案:方案1:使用替代的接口ISampleGrabber,代替IBasicVideo,具体调用的函数为:ISampleGrabber::GetCurrentBuffer.可以参考文章:dshow中使用SampleGrabberfilter抓取图像。在我的开发环境win10+vs2013下没能找到ISampleGrabber接口;而在官方文档中提到ISa…

    2022年9月24日
    0
  • 回溯法解决01背包问题算法_01背包问题伪代码

    回溯法解决01背包问题算法_01背包问题伪代码0-1背包问题,在搜索过程中使用递归来完成。packagecom.test;classPack{intn=8;//物品个数intW=110;//背包总容量int[]Weights={1,11,21,23,33,43,45,55};//重量数组int[]Values={11,21,31,33,43,53,55,65};//价值数组intbestValu…

    2022年10月9日
    0
  • HP Loadrunner 11 安装+激活成功教程+汉化+乱码

    HP Loadrunner 11 安装+激活成功教程+汉化+乱码一、激活成功教程HPLoadrunner+汉化1、在HP官网上注册(必须要注册才能下载)2、下载LoadRunner11安装包  下载地址:http://www8.hp.com/cn/zh/software-solutions/software.html?compURI=1175451#-HPCDC-trackGatedLink=TrialSoftware|3-3KSG8SS|T

    2022年7月22日
    17
  • 我的第一个上位机软件「建议收藏」

    我的第一个上位机软件「建议收藏」2019年即将过去,这一年最值得开心、高兴的事就是我参与研发的“全自动生化分析仪”终于上市了,并受到市场的欢迎;由于有非常给力的销售团队,机器的订单一直不断。当然机器研制成功是项目经理和团队的功劳,而我只是参与其中的一部分而已,但这对我而言有特殊的意义;因为这是我的第一个基于linux的商用上位机软件。虽然以前在windows平台折腾过java、C#、MFC的小上位机,但那些上位机无…

    2022年5月31日
    44

发表回复

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

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