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

学会qsort了,纪念,贴代码

Posted by speedcell4 at 2011-03-15 14:26:56 on Problem 3664
#include<iostream>
using namespace std;
int n,k;
struct node
{
    int a;
    int b;
    int index;
};
int cmpa(const void *a,const void *b)
{
    return (*(node *)b).a-(*(node *)a).a;
}
int cmpb(const void *a,const void *b)
{
    return (*(node *)b).b-(*(node *)a).b;
}
int main()
{
    cin>>n>>k;
    struct node kan[50000];
    for(int i=0;n-i;i++)
    {
        cin>>kan[i].a>>kan[i].b;
        kan[i].index=i+1;
    }
    qsort(kan,n,sizeof(struct node),cmpa);
    qsort(kan,k,sizeof(struct node),cmpb);
    cout<<kan[0].index<<endl;
}

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