-
Title Description:
-
Zhejiang Tongxiang Wu Town A total of n individuals, please find the town of the former m monopoly.
-
Input:
-
The input contains multiple sets of test cases.
Each use case first contains 2 integers n (0<n<=100000) and M (0<m<=10), Where: N is the number of people in town, M is the number of millionaires that need to be found, and the next line is to enter the wealth value of N people in the town.
N and m at 0 indicate the end of the input.
-
Output:
-
please output wuzhen former M monopoly property number, property of the row front, if the monopoly less than m, then all output, each group of output accounted for a row.
-
Sample input:
-
3 12 5-15 31 2 3 4 50 0
-
Sample output:
-
55 4 3
-
Source:
-
2009 Zhejiang University computer and software engineering research on the real problem of life test
-
Answering:
-
problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-7758-1-1.html
#include <stdio.h> #include <stdlib.h> int compare (const void *p,const void *q) {return * (int *) q-* (int *) p; } int main () {int n,m; int a[100000]; int i; while (scanf ("%d%d", &n,&m)!=eof&&n!=0&&m!=0) {for (i=0;i<n;i++) scanf ("%d", &a[i]); Qsort (a,n,sizeof (int), compare); if (m>n) {for (i=0;i<n;i++) {if (i!=0) printf (""); printf ("%d", a[i]); }} else{for (i=0;i<m;i++) {if (i!=0) printf ("") ; printf ("%d", a[i]); }} printf ("\ n"); } return 0;} /************************************************************** problem:1034 user:vhreal language:c Result: Accepted time:30 Ms memory:1240 kb****************************************************************/
Nine degrees oj-topic 1034: Looking for a Millionaire