1718:Rank

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1718

方法:排序

思路:这道题本身难度还不算高,主要是有一个坑,一开始排序的时候,若出现成绩一样的情况,我在cmp函数里做了按字典序排列的处理,但是后来发现这道题目实际上是要求允许出现并列的情况,比如第一名100分,第二名33分的有两个人,再往下就是第四名了,因此排序完成后只需要统计多少个人比指定哪个人高,再加1就是要求的人数。

难点:绕开那个坑即可

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct info
{
    int stunum;
    int score;
}stu[1000+10];
bool cmp(info a,info b)
{
    if(a.score!=b.score)
        return a.score>b.score;
    else if(a.score == b.score)
        return a.stunum < b.score;
}
int main()
{
    int selfnum;
    int i;
    while(cin>>selfnum)
    {
        for(i = 1;i <= 1000;i++)
        {
            cin>>stu[i].stunum>>stu[i].score;
            if(stu[i].stunum == 0 &&stu[i].score == 0)
                break;
        }
        sort(stu+1,stu+i,cmp);
        int counter = 0;
        int mark = 0;
        for(int j = 1;j <= i;j++)
        {
            if(selfnum == stu[j].stunum)
            {
                mark = j;
                break;
            }
        }
        for(int j = 1;j <= i;j++)
        {
            if(stu[j].score > stu[mark].score)
                counter++;
        }
        cout<<counter+1<<endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值