快速排序||特殊情况分析
1 . 题目描述
4th IIUC Inter-University Programming Contest, 2005 | |
A | Children’s Game |
Input: standard input | |
Problemsetter: Md. Kamruzzaman |
There are lots of number games for children. These games are pretty easy to play but not so easy to make. We will discuss about an interesting game here. Each player will be given N positive integer. (S)He can make a big integer by appending those integers after one another. Such as if there are 4 integers as 123, 124, 56, 90 then the following integers can be made – 1231245690, 1241235690, 5612312490, 9012312456, 9056124123 etc. In fact 24 such integers can be made. But one thing is sure that 9056124123 is the largest possible integer which can be made.
You may think that it’s very easy to find out the answer but will it be easy for a child who has just got the idea of number?
Input
Each input starts with a positive integer N (≤ 50). In next lines there are N positive integers. Input is terminated by N = 0, which should not be processed.
Output
For each input set, you have to print the largest possible integer which can be made by appending all the N integers.
Sample Input | Output for Sample Input |
4 | 9056124123 |
2 .测试用例
2212 221
5
999999
注:这里要特别注意第一组测试用例,这种情况为这道题的特殊情况
3 . 算法描述
1. 主体思路:
2. 算法实现细节
3.利用2的方法,在(n+1)*s2.length()大小内一定能分出大小。下面证明下这个结论 a.s3与s2部分重叠 b.s1与s2添加新的填充字符s2 c.这种情况等价于将s1与s1错位s3.length()位比较,如果s2的各个位置不是全部一样,那么一定可以找打有差异的哪一位,并判断大小(s1 = 2212,s2=221,s3=2。按照之前的证明,其实最后的比较是s2错一位与自己比较,一定可以分出大小)
4 .程序中遇到的问题
5. 需要改进的地方
6.代码