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年5月13日
    36
  • 在树莓派4B上使用YOLO v3 Tiny进行实时目标检测

    在树莓派4B上使用YOLO v3 Tiny进行实时目标检测首先尝试使用yolo官网yolo给的教程,在树莓派上测试,但是在运行时出现段错误,尝试很多方法无法解决。在国外的网站找到darknet-nnpack这个东西,可以完美的在树莓派上运行。参考的文章darknet-nnpackhttps://github.com/zxzhaixiang/darknet-nnpackFunofDIYhttp://funofdiy.blogspot.c…

    2022年6月9日
    62
  • MyBatis-Plus 之逻辑删除

    MyBatis-Plus 之逻辑删除MyBatis-Plus之逻辑删除实现概念逻辑删除:文件没有被真正的删除,只不过是文件名的第一个字节被改成操作系统无法识别的字符,通常这种删除操作是可逆的,就是说用适当的工具或软件可以把删除的文件恢复出来。物理删除:指文件存储所用到的存储区域被真正的擦除或清零,这样删除的文件是不可以恢复的,物理删除是计算机处理数据时的一个概念。逻辑删除就是对要被删除的数据打上一个删除标记,在逻辑上,数据是被删除了,但数据本身依然存在!而物理删除则是把数据从介质上彻底删除掉。正文首先创建一个数据库表,如下图

    2022年5月20日
    49
  • 深度学习图像标注工具汇总

    深度学习图像标注工具汇总对于监督学习算法而言,数据决定了任务的上限,而算法只是在不断逼近这个上限。世界上最遥远的距离就是我们用同一个模型,但是却有不同的任务。

    2022年6月1日
    39
  • urlencode()与urldecode()

    urlencode()与urldecode()

    2021年10月21日
    45
  • docker pycharm 连接_pycharm远程连接docker开发[通俗易懂]

    docker pycharm 连接_pycharm远程连接docker开发[通俗易懂]1配置docker服务端(c/s架构)允许远程客户端连接-1vim/lib/systemd/system/docker.service…#ExecStart=/usr/bin/dockerd-Hfd://–containerd=/run/containerd/containerd.sockExecStart=/usr/bin/dockerd-Htcp://0.0.0.0:2…

    2022年8月27日
    7

发表回复

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

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