"String sort, tricks!" "UVa 10905-children ' s Game

Source: Internet
Author: User

There is lots of number games for children. These games is pretty easy-to-play but not so easy-to-make. We'll discuss about a interesting game here. Each player would be given N positive integer. S He can make a big integer by appending those integers after one another. Such as if there is 4 integers as 123, 124,, and the following integers can be made–1231245690, 1241235690, 5612 312490, 9012312456, 9056124123 etc. In fact such integers can is made. But one thing are sure that 9056124123 are the largest possible integer which can be made.

Think that it's very easy-to-find out the the answer but would it is easy for a child who had just got the idea of numb Er?

Input

Each of the input starts with a positive integer N (≤50). In next lines there is N positive integers. Input is terminated by N = 0, which should isn't be processed.

Output

For each of the input set, you had to print the largest possible integer which can is made by appending all the N integ ERs.

Sample Input

4
123 124 56 90
5
123 124 56) 90 9
5
9 9 9) 9 9
0

Output for Sample Input

9056124123
99056124123
99999

Test instructions: the maximum string combination;

1 BOOL cmp (stringstring  b)2{3      return a+b > B +A; 4 }

Skill is more strong. Pay attention to the use of similar types of problems;

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <string>6#include <vector>7#include <algorithm>8 using namespacestd;9 Const intMAXN = -;Ten stringSTR[MAXN]; One BOOLcmpstringAstringb) A { -     returnA+b > B +A; - } the intMain () - { -     intN; -      while(Cin >> N &&N) +     { -          for(inti =0; I < n; i++) +CIN >>Str[i]; ASort (str, str+N, CMP); at          for(inti =0; I < n; i++) -cout <<Str[i]; -cout <<Endl; -     } -     return 0; -}
View Code

"String sort, tricks!" "UVa 10905-children ' s Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.