讨论 / C++ STL sort函数版(为什么用STL的人这么少)
DavidTesla 2016-06-24 01:52:50
点我顶贴 收藏 删除
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

struct str{

int k;

int s;

}p[5005];

bool cmp(str A,str B);

int main()

{

int m,n,low,count=0,num;

scanf("%d%d",&n,&m);

for(int q=1;q<=n;q++)

scanf("%d%d",&p[q].k,&p[q].s);

sort(p+1,p+1+n,cmp);

num=(int)m*1.5;

low=p[num].s;

for(int q=num;;q++){

if(p[q].s!=low)

break;

count++;

}

printf("%d %d\n",low,num+count-1);

for(int q=1;q<=num+count-1;q++)

printf("%d %d\n",p[q].k,p[q].s);

return 0;

}

bool cmp(str A,str B)

{

if(A.s!=B.s)

return A.s>B.s;

else

return A.k<B.k;

}

查看更多回复
提交回复