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


相关推荐

  • matlab 柱状图不同颜色(取巧哈)[通俗易懂]

    matlab 柱状图不同颜色(取巧哈)[通俗易懂]以前写过一个颜色索引的柱状图,但是年代久远想不起来了。今天需要出一个不同颜色的柱状图,看了一下博客,首先使用了matlab中的children,但是发现颜色没有变化。后来从另外的博客中发现,matalb2014以后的版本这个功能不能用了,what?只能用bar。好吧,用bar一遍一遍写,这里做个取巧的方式哈。mydata=[0.5,1.5,2.5,3.5,4.5];figure(1)holdonfori=1:length(mydata)h=bar(i,mydata.

    2022年10月10日
    0
  • 基于mips内核的Atheros芯片–wlan中的VAP的创建「建议收藏」

    基于mips内核的Atheros芯片–wlan中的VAP的创建「建议收藏」重要是使用命令创建,可以通过无线网卡和手机登陆的无线网络标识。登陆名称就是ssid号。1:/etc/rc.d/rc.wlanup//这个文件主要用来加载wlan相应的驱动程序。2:配置ip地址,针对br0。ifconfigbr010.10.99.194up  3:创建基本的VAP/etc/rc.d/rc.wlanupwlanconfigath0creat

    2025年6月9日
    4
  • editormd_editorialize

    editormd_editorialize使用editormd图片上传无法返回路径问题内部再生成json时会自动添加一些没必要的多余字段在此处添加一行只取body中pre第一个数据

    2025年8月24日
    2
  • Redis-主从复制和哨兵模式

    主从复制指的是把一台Redis服务器的数据复制到其他Redis服务器上,前者称为主节点Master,后者称为从节点Slave,只能从Master单向复制到Slave,一般Master以写操作为主,Slave以读操作为主,实现读写分离。

    2022年4月8日
    33
  • Java 二维数组反转「建议收藏」

    Java 二维数组反转「建议收藏」通过交换下标实现反转操作:publicclassTestFile{ publicstaticvoidmain(String[]args){ int[][]arr={{1,2,3},{4,5,6},{7,8,9}}; int[][]toarr=newint[3][3]; System.out.println("反转前"); intk=…

    2022年6月11日
    55
  • getelementbyid属性与用法[通俗易懂]

    getelementbyid属性与用法[通俗易懂]语法:oElement=document.getElementById(sID)参数:sID――必选项。字符串 (String) 。返回值:oElemen――对象 (Element) 。说明:根据指定的 id 属性值得到对象。返回 id 属性值等于 sID 的第一个对象的引用。假如对应的为一组对象,则返回该组对象中的第一个。 如果无符合条件的对象,则返回 nul

    2022年7月15日
    44

发表回复

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

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