| ||||||||||
| 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 | |||||||||
我也是这样写的,是不是比较函数有问题,不怎么懂,哪位帮我看看#include "stdio.h"
#include "stdlib.h"
#include "math.h"
struct song{
int id;
int ln;
double fr;
}a[1<<16];
int cmp(const void *p1,const void *p2)
{
if( (*(struct song *)p2).fr>(*(struct song *)p1).fr )
return 1;
if( fabs((*(struct song *)p2).fr==(*(struct song *)p1).fr)<0.000001 )
return 0;
return -1;
}
int main()
{
int i,n,num;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d %lf",&a[i].id,&a[i].ln,&a[i].fr);
a[i].fr/=a[i].ln;
}
scanf("%d",&num);
qsort(a,n,sizeof(struct song),cmp);
printf("%d\n",a[num-1].id);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator