| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
又一个用qsort搞定的水题!#include <stdio.h>
struct ab{
int id;
int first;
int second;
}abc[50000];
int cmp1(const void *a, const void *b){
return ((struct ab *)a)->first - ((struct ab *)b)->first;
}
int cmp2(const void *a, const void *b){
return ((struct ab *)a)->second - ((struct ab *)b)->second;
}
int main()
{
int n,k, i;
scanf("%d%d", &n,&k);
for(i = 0; i < n; i++){
scanf("%d%d",&abc[i].first, &abc[i].second);
abc[i].id = i + 1;
}
qsort((void *)abc, n,sizeof(abc[0]),cmp1);
qsort((void *)(&abc[n - k]), k,sizeof(abc[0]),cmp2);
printf("%d\n", abc[n-1].id);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator