您的位置:首页 > 其它

第六题 Sort对于超大量的数据输出前n个最大的数据(思想还是hash)

2017-11-22 21:12 225 查看
//这一次居然是因为这里的j++写成了j--我也是醉了。。

//不要挤着眼敲代码,你还没到那个时候!!!!!

#include <stdio.h>

#include <math.h>

#include <algorithm>

#include <string.h>

using namespace  std;

int buf[1000001];

int main()

{

    int n;

    int m;

    int tmp;

    while(scanf("%d%d",&n,&m)!=EOF)

    {

        memset(buf,0,sizeof(int));

        for(int i=0;i<n;i++)

        {

            scanf("%d",&tmp);

            buf[tmp+500000]++;

        }

        int cnt=0;

        for(int j=1000000;j>=0;j--)//这一次居然是因为这里的j++写成了j--我也是醉了。。

        {

            if(cnt==m)break;

            if(buf[j])

            {

               cnt++;

               printf("%d ",j-500000);

            }

        }

        printf("\n");

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐