String processing for digital games in the first ACM competition of Hunan University of Technology

Source: Internet
Author: User

Digital gamesTime limit (Common/Java): 1000 ms/3000 Ms running memory limit: 65536 Kbyte
Total submissions: 53 passed tests: 10

Description

 

Nowadays, there are many digital games for children. These games are simple to play, but it is not that easy to create one. Here we will introduce an interesting game.

You will get n positive integers. You can take an integer after another integer to create a larger integer. For example, there are 4 numbers 123,124, 56, 90, and they can make the following integers-1231245690,124 1235690, 5612312490,901 2312456, 9056124123 .... A total of 24 (4 !) Type. But 9056124123 is the largest one.

You may think this is a simple task, but is it a simple task for a digital child?

Input

Enter multiple groups of test materials. The first column is a positive integer n (n <= 50). The next column contains n positive integers. If n = 0, the input ends.

Output

Output a column for each test data. The output uses the N Integers to combine them into the maximum integer.

Sample Input

4
123 124 56 90
5
123 124 56 90 9
5
9 9 9 9 9
3
12 123 1231
0

Sample output

9056124123
99056124123
99999
123123112

Prompt

For such questions, you can enter the following methods:

int n;while(scanf("%d", &n) != EOF){    your code...}

  

It seems to be a mathematical question, but everyone knows that this is a Sort question, and it is not a general sort. In this example, we can see that it only relies on one strcmp (no other processing) it cannot be correctly sorted. Although "124" and "123" can be correctly handled, "90" and "9" cannot be correctly arranged, 90 corresponds to '9' '0' \ 0' and 9 corresponds to '9' \ 0'. The strcmp function determines that a string ends, '\ 0' is equal to 0 in values, so "90"> "9", but actually "909" <"990 ", here we can find a sorting idea. We can determine which two adjacent strings are positive and reverse, and then use the strcmp function at this time, sort by splicing mode with a higher priority.

 

The Code is as follows:

 

# Include <stdio. h> # include <stdlib. h> # include <math. h> # include <string. h> # include <time. h> char STR [55] [1000]; int CMP (const void * a, const void * B) {char P1 [1000], P2 [1000]; // In the competition, the array is small, and ...... strcpy (P1, (char *) A); // do temporary storage, this is because the array is the relationship between the pointer constant strcpy (P2, (char *) B); strcat (P1, (char *) B); // do not splice a and B directly. Strcat (P2, (char *) A); Return strcmp (P2, P1);} int main () {int N; while (scanf ("% d ", & N), n) {for (INT I = 0; I <n; ++ I) scanf ("% s", STR [I]); qsort (STR, n, sizeof (STR [0]), CMP); For (INT I = 0; I <n; ++ I) printf ("% s ", STR [I]); puts ("");} return 0 ;}

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.