Millionaire rank listtime limit: 1000 ms
Memory limit: 131072 kbdescription
In the wild universe, there lives a race of clever creature. They have high level civilization and control a lot of planets.
As we human, some of us are very rich and the public like to know who are the top 10. as a journalist of a famous new paper, you are asked to write a program to get the top 10 list.
Input
The input contains only one test case.
The first line contains one integer N (10 <= n <= 1,000,000), which means there are n rich people in the race. the following n lines each contains a integer mi (mi> = 0), which means the money of the I-th person.
But as they are universal millionizer, they are very rich, which means the amount of their money can be as large as 1025.
Note that MI may have preceding zeros.
Output
Output 10 lines, containing the money of the richest 10 people in descending order. Delete the preceding zeros if they once have.
Sample Input
111234567891015
Sample output
151098765432
Source: 34th ACM/ICPC Asia Regional, Hefei, preliminary
Solution:
Sorting of large numbers. For large numbers, it is generally faster to read in C language. You only need to sort the top 10 sorting methods.
# Include <iostream> # include <cstring> using namespace STD; # define maxsize 1000000 char money [maxsize] [26]; bool compare (char a [], char B []) {int I, alength = strlen (A), blength = strlen (B); If (alength! = Blength) return alength> blength; else for (I = 0; I <alength; I ++) if (a [I]! = B [I]) return a [I]> B [I]; return 1 ;}int main () {int N, J, I; char temp [26]; scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% s ", & money [I]) ;}for (I = 0; I <10; I ++) for (j = I + 1; j <n; j ++) if (compare (money [J], money [I]) {strcpy (temp, money [I]); strcpy (money [I], money [J]); strcpy (money [J], temp) ;}for (I = 0; I <10; I ++) {printf ("% s/n ", money [I]);} return 0 ;}