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月2日 下午9:00
下一篇 2022年1月2日 下午10:00


相关推荐

  • java取整函数

    向上取整Math.ceil()向上取整:比自己大的最小整数ceil是天花板的意思,表示向上取整,用数学符号⌈⌉表示Math.ceil(6.1)=7.0Math.ceil(6.9)=7.0向下取整Math.floor()向下取整:比自己小的最大整数floor是地板的意思,表示向下取整,用数学符号⌊⌋表示Math.floor(9.1)=9.0Math.floor(9.9)=10.0Math.round()四舍五入后取整,其算法为Math.round(x+0

    2022年4月8日
    115
  • 数据库的数据模型是网状模型_网状模型的数据结构是

    数据库的数据模型是网状模型_网状模型的数据结构是层次数据模型    定义:层次数据模型是用树状<层次>结构来组织数据的数据模型。    满足下面两个条件的基本层次联系的集合为层次模型    1.有且只有一个结点没有双亲结点,这个结点称为根结点    2.根以外的其它结点有且只有一个双亲结点其实层次数据模型就是的图形表示就是一个倒立生长的树,由基本数据结构中的树(或者二叉树)的定义可知,每棵树都有且仅有一个根节点,其余的…

    2025年6月28日
    6
  • 布隆过滤器的原理,使用场景和注意事项有哪些_布隆过滤器的基本工作原理

    布隆过滤器的原理,使用场景和注意事项有哪些_布隆过滤器的基本工作原理目录什么是布隆过滤器实现原理为啥不用HashMap的问题布隆过滤器数据结构支持删除么如何选择哈希函数个数和布隆过滤器长度最佳实践Redis大Value拆分参考资料什么是布隆过滤器本质上布隆过滤器是一种数据结构,比较巧妙的概率型数据结构(probabilisticdatastructure),特点是高效地插入和查询,可以用来告诉你“某样东西一定不存在或者可能存在”。相比于传统的List、Set、Map等数据结构,它更高效、占用空间更少,但是缺点是其返回的结果是概率性的,而不是确切的。实现

    2026年4月16日
    7
  • 配置JDK环境变量(最简单手把手教程)

    配置JDK环境变量(最简单手把手教程)​目录简介JDK卸载准备JDK环境配置校检配置简介本文博客只为自己记忆,就新手最简单手把手教程JRE(JavaRuntimeEnvironment)Java运行环境,用来运行

    2022年7月1日
    28
  • 将JS对象转换为JSON字符串

    将JS对象转换为JSON字符串如果我用以下方法在 JS 中定义了一个对象 varj name binchen 如何将对象转换为 JSON 输出字符串应为 name binchen

    2026年3月18日
    0
  • C语言switch史上最详细的讲解

    C语言switch史上最详细的讲解原文链接 https github com shellhub blog issues 41C 语言 switch 史上最详细的讲解 switch 语句允许测试变量与值列表的相等性 每个值称之为案例或者 case 程序会检查 switch 后面的值并且与 case 后面的值比对 如果相等则执行后面的代码或代码块语法 switch 在 C 语言中的语法如下 switch expression cas

    2026年3月26日
    2

发表回复

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

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