Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我也是这样写的,是不是比较函数有问题,不怎么懂,哪位帮我看看

Posted by zerocool_08 at 2005-10-23 15:56:36 on Problem 2675
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator