Nine degrees oj-topic 1034: Looking for a Millionaire

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.