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("+");
	}
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/117614.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • docker端口映射无法外部访问_docker用户映射

    docker端口映射无法外部访问_docker用户映射端口映射容器中可以运行一些应用,要让外部也可以访问这些应用,可以通过-P或-p参数来指定端口映射。当使用大写的-P标记时,Docker会随机映射一个物理机的49000~49900之间的端口到内部容器开放的网络端口。-p则可以指定想要映射的物理机端口,并且,在一个指定端口上只可以绑定一个容器。1.映射指定的本地IP和端口到容器端口dockerrun-it-p192.168.10.10:8000:80busybox2.映射本地指定IP的任意端口到

    2022年10月18日
  • navicat2021激活码【中文破解版】

    (navicat2021激活码)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.cn/100143.html3Y…

  • python文件操作步骤_python读取csv文件

    python文件操作步骤_python读取csv文件文件操作文件操作主要包括对文件内容的读写操作,这些操作是通过文件对象实现的,通过文件对象可以读写文本文件和二进制文件open(file,mode='r',buffering=-

  • 微信小程序实例系列怎么做_小程序制作教程免费

    微信小程序实例系列怎么做_小程序制作教程免费下载微信小程序实现部分高德地图功能的DEMO下载微信小程序实现MUI的部分效果的DEMO下载更多微信小程序实例GITGIT地址https://github.com/Rattenking/WXTUI-DEMOGIT下载gitclonehttps://github.com/Rattenking/WXTUI-DEMO.git常见…

  • tinyXml生成XML文件

    tinyXml生成XML文件1.tinyXMl生成XML文件#include<stdio.h>#include<string>usingnamespacestd;#include”../tinyxml/tinyxml.h”inttest1(){ TiXmlDocumentxml_doc; //添加XML声明 xml_doc.LinkEndChild(n…

  • mysql常用的窗口函数_窗口函数和groupby一起用

    mysql常用的窗口函数_窗口函数和groupby一起用本博客转自:https://blog.csdn.net/weixin_34384915/article/details/87551597窗口函数(OLAP实时分析处理函数),可以一般聚合函数无法实现的高级操作。诸如排序、生成序列号等功能。目前DBMS逐步都完成了对窗口函数的支持,唯独MySql不支持(但是Mysql8开始支持了)。1.窗口函数语…

发表回复

您的电子邮箱地址不会被公开。

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