zoukankan      html  css  js  c++  java
  • Hdu3785

    <span style="color:#6600cc;">/*
    G - 寻找大富翁
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit
    
    Status
    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 1
    2 5 -1
    5 3
    1 2 3 4 5
    0 0
    
    Sample Output
    5
    5 4 3
    By Grant Yuan
    2014.7.11
    */
    #include<iostream>
    #include<stdio.h>
    
    #include<stdlib.h>
    #include<string.h>
    using namespace std;
    int n,m;
    int a[100003];
    int cmp(const void *a,const void *b)
    {
        return(*(int*)b-*(int*)a);
    }
    int main()
    {int i,j;
        while(1){
          cin>>n>>m;
          if(n==0&&m==0)
             break;
        for(i=0;i<n;i++)
           cin>>a[i];
        qsort(a,n,sizeof(a[0]),cmp);
          for(j=0;j<m;j++)
            if(j==0) cout<<a[j];
            else cout<<" "<<a[j];
            cout<<endl;
    
            }
            return 0;
    }
    </span>


  • 相关阅读:
    Leetcode题解(十六)
    Leetcode题解(十五)
    Leetcode题解(十四)
    Leetcode题解(十三)
    Leetcode题解(十二)
    Leetcode题解(十一)
    php数据库访问及增删改
    克隆对象及加载类
    抽象
    PHP继承
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254541.html
Copyright © 2011-2022 走看看