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)


相关推荐

  • JSP的6种乱码解决方案「建议收藏」

    JSP的6种乱码解决方案「建议收藏」JSP的6种乱码解决方案

  • 大数据常用十种开发语言[通俗易懂]

    大数据常用十种开发语言[通俗易懂]随着大数据热潮持续延烧,几乎每个产业都有如洪水般倾泻的信息,面对上万笔的顾客浏览纪录、购买行为数据,如果要用Excel来进行数据处理真是太不切实际了,Excel相较于其他统计软件的功能已相去甚远;但如果只会操作统计软件而不会用逻辑分析数据背后的涵义与事实现况相应证的话,那也不过只能做数据处理,替代性很高的工作,而无法深入规划策略的核心。  当然,基本功是最不可忽略的环节,想要成为数据

  • 解析MP4文件中的sps和pps[通俗易懂]

    解析MP4文件中的sps和pps[通俗易懂]一、MP4格式基本概念MP4格式对应标准MPEG-4标准(ISO/IEC14496) 二、MP4封装格式核心概念1 MP4封装格式对应标准为ISO/IEC14496-12(信息技术视听对象编码的第12部分:ISO基本媒体文件格式/InformationtechnologyCodingofaudio-visualobjectsPart12

  • Java中Scanner的用法:单行/多行输入

    Java中Scanner的用法:单行/多行输入Java的Scanner用法,主要用于算法笔试时的控制台输入问题:解决这种情况下的Scanner输入:单行,多行,数值,字符串最好解决的情况单行输入多个字符串多行输入多个字符串问题:解决这种情况下的Scanner输入:单行,多行,数值,字符串平时写程序一般不用Scanner,线上笔试的时候,各大公司热衷于Scanner输入。平时用LeetCode刷题也不会用到,结果多次在笔试时候卡在Scan……

  • 域名、服务器、IP之间的关系[通俗易懂]

    域名、服务器、IP之间的关系[通俗易懂]文章转载自:[https://www.jianshu.com/p/c3d3f6629c13](https://www.jianshu.com/p/c3d3f6629c13)本文主要针对域名、服务器和IP之间的关系进行介绍,并通过实际案例讲解域名解析过程本文目录基础概念案例分析阿里云域名解析过程基础概念服务器:服务器其实就像我们的家用电脑一样,也有主板、CPU、内存、硬盘、电源等。根据功能来说服务器可分为web服务器、ftp服务器、数据库服务器、邮件服务器等等,做什么用途就可以叫做什么服务器

  • java 差的绝对值_java 绝对值问题[通俗易懂]

    /**输入一个正整数repeat(0/**输入一个正整数repeat(0读入1个正实数eps,计算并输出1-1/3+1/5-1/7+……,直到最后一项的绝对值小于eps为止(要求每一项的绝对值均大于等于eps,并以float类型输出数据)。例:括号内是说明输入2(repeat=2)1E-40.1输出0.78534820.83492064*/importjava.util.Scanner…

发表回复

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

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