#C7748. Construct the Largest Number
Construct the Largest Number
Construct the Largest Number
Given a list of non-negative integers, arrange them such that they form the largest possible number. The answer should be returned as a string. This problem requires you to combine the integers by ordering them optimally. In particular, for two numbers \(a\) and \(b\), you should decide the order based on the comparison of the concatenated strings \(a\,b\) and \(b\,a\).
Input Format: The input is read from stdin
. The first line contains an integer \(n\) representing the number of elements. The second line contains \(n\) non-negative integers separated by spaces.
Output Format: Output the largest number (as a string) that can be formed by concatenating the given numbers. The result should be printed to stdout
.
Note: If the constructed number has leading zeros, the output should be "0".
inputFormat
The input is provided via stdin
with the following format:
- The first line contains an integer \(n\) denoting the number of elements.
- The second line contains \(n\) non-negative integers separated by spaces.
outputFormat
Print to stdout
the largest number that can be formed by concatenating the integers from the input. The output should be a single string.
2
10 2
210