Description
Give you n integers, and output the first m in the ascending order.
Input
Each group of test data has two rows. The first row has two numbers n, m (0 <n, m <1000000), and the second row contains n different rows, and all are integers in the range.
Output
Test data in each group is output in the ascending order of the first m.
Sample Input
5 3 3-35 92 213-644
Sample Output
213 92 3 source code:
# Include <stdio. h ># include <algorithm> using namespace std; struct p {int x;} digit [1000000]; // overflow if it is defined as digit [1000000. However, struct will not overflow. // why? Bool cmp (p a, p B) {return. x> B. x ;}int main () {int M, N; while (scanf ("% d", & N, & M )! = EOF) {int I; for (I = 0; I <N; I ++) scanf ("% d", & digit [I]. x); sort (digit, digit + N, cmp); for (I = 0; I <M; I ++) {if (I = 0) printf ("% d", digit [I]. x); else printf ("% d", digit [I]. x);} printf ("\ n");} return 0 ;}
Tips:
Why ??? Why do we understand the AC as a structure? But not directly using arrays?
First m big data