Looking for a Millionaire
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4169 Accepted Submission (s): 1714
Problem description Zhejiang Tongxiang Wu Town A total of n people, please find out the town of the former m monopoly.
Input inputs contain 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 export the wealth of the former m monopoly of Wuzhen, the number of assets in front of the row, if the monopoly less than m, then all output, each group of output accounted for one row.
Sample Input
3 12 5-15 31 2 3 4 50 0
Sample Output
55 4 3
SOURCE Zhejiang University Computer Postgraduate exam on the machine-2009
A problem with water, wrote for 10 minutes on AC again.
Put a code on it.
#include <stdio.h> #include <algorithm> #define WBX 100005 //n The value of the 100000 array to open to more than 10W. int a[wbx];using namespace STD; #include <string.h>int main () {int n,m,i;while (scanf ("%d%d", &n,&m)!=eof, n!=0,m!=0) //m and N are 0 at the same time to end directly. {memset (a,0,sizeof (a)); for (i=1;i<=n;i++) scanf ("%d", &a[i]); sort (a+1,a+1+n) ; Ascending. if (n<m) // less than M direct output. {for (i=n;i>=1;i--) {if (i!=1) printf ("%d", A[i]), elseprintf ("%d\n", A[i]);} } else // otherwise {for (i=n;m>0;i--, m--) {if (m==1) // M is one when the last person is output and the line is wrapped. printf ("%d\n", A[i]), Else printf ("%d", A[i]); Otherwise, the output is descending and there are spaces between the outputs. }}}return 0;}
HDU 3785 looking for a millionaire.