1160 -- 寻找大富翁

来源:互联网 发布:淘宝刷单91lingla 编辑:程序博客网 时间:2024/05/24 20:07

寻找大富翁

Time Limit:1000MS  Memory Limit:65536K
Total Submit:72 Accepted:48

Description

浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁.

Input

输入包含多组测试用例.
每个用例首先包含2个整数n(0 < n <= 100000)和m( 0 < m <= 10),其中: n为镇上的人数,m为需要找出的大富翁数, 接下来一行输入镇上n个人的财富值.
n和m同时为0时表示输入结束.

Output

请输出乌镇前m个大富翁的财产数,财产多的排前面,如果大富翁不足m个,则全部输出,每组输出占一行.

Sample Input

3 12 5 -15 31 2 3 4 50 0

Sample Output

55 4 3

Source

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;    namespace AK1160 {        class Program {            static void Main(string[] args) {                string sb;                while ((sb = Console.ReadLine()) != null) {                    string[] s = sb.Split();                    int n = int.Parse(s[0]), m = int.Parse(s[1]);                    if (n + m == 0) break;                    string[] b = Console.ReadLine().Split();                    int[] count = new int[1100];                    for (int i = 0; i < n; i++)                        count[i] = int.Parse(b[i]);                    Array.Sort(count, 0, n);                    for (int i = n - 1; i >= n - m; i--)                        Console.Write(count[i] + " ");                    Console.WriteLine();                }            }        }    }


0 0
原创粉丝点击