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


相关推荐

  • 30天自制操作系统之第13天 定时器(2)

    30天自制操作系统之第13天 定时器(2)

    2021年12月14日
  • awk 用法示例大全[通俗易懂]

    awk 用法示例大全[通俗易懂]文章目录#删除temp文件的重复行awk’!($0inarray){array[$0];print}’temp#查看最长使用的10个unix命令awk'{print$1}’~/.bash_history|sort|uniq-c|sort-rn|head-n10#查看机器的ip列表ifconfig-a|awk’/Bcast/{print$2}’|cut-c5-19#查看机器的每个远程链接机器的连接数netstat-ant

    2022年7月11日
  • 前端技术栈总结_前端开发技术栈

    前端技术栈总结_前端开发技术栈vuereact

    2022年10月25日
  • 异步处理FutureTask实例「建议收藏」

    异步处理FutureTask实例「建议收藏」   在Web应用前端,AJAX有同步和异步处理,异步可以避免阻塞。在WEB后端一般业务应用大多为同步处理,但也有一些需要异步处理的场合,比如A系统调B系统接口I,但B系统处理时间很长,这时,A系统主线程不能一直阻塞等待,可以使用异步处理。即先调用接口I,随即做后面的处理,等B系统返回值时再进行返回后处理。时序为:A:invokeIA:dootherthingB:处理完成,…

    2022年6月17日
  • 利用STM32F103精确控制步进电机「建议收藏」

    利用STM32F103精确控制步进电机「建议收藏」**利用STM32F103控制步进电机精确角度转动**欢迎使用Markdown编辑器你好!这是你第一次使用Markdown编辑器所展示的欢迎页。如果你想学习如何使用Markdown编辑器,可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。新的改变我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,…

    2022年6月1日
  • mysql之group_concat函数详解[通俗易懂]

    mysql之group_concat函数详解[通俗易懂]函数语法:group_concat([DISTINCT]要连接的字段[OrderBY排序字段ASC/DESC][Separator‘分隔符’])下面举例说明:selectid,pricefromgoods;以id分组,把price字段的值在同一行打印出来,逗号分隔(默认)selectid,group_concat(price…

    2022年6月13日

发表回复

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

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