Codeforces 1017A The Rank 题解

题目链接:

http://codeforces.com/problemset/problem/1017/A

Description

John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.
There are n students, each of them has a unique id (from 1 to n). Thomas’s id is 1. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.Please help John find out the rank of his son.

Input

The first line contains a single integer n(1≤n≤1000) — the number of students.
Each of the next n lines contains four integers ai, bi, ci, and di (0≤ai,bi,ci,di≤100) — the grades of the i-th student on English, German, Math, and History. The id of the i-th student is equal to i.

Output

Print the rank of Thomas Smith. Thomas’s id is 1

提示:

这是一道很简单的排序题,给出4个科分数,按从大到小排名,总分相同按id从小到大排。合理应用sort即可。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 1001
using namespace std;
struct mrz
{
    int id,sco;
} p[N];
bool cmp(mrz k1,mrz k2)
{
    if(k1.sco!=k2.sco) return k1.sco>k2.sco;
    else return k1.id<k2.id;
}
int n,ls;
int main()
{
    scanf("%d",&n);
    memset(p,0,sizeof(p));
    for(int i=1;i<=n;i++)
    {
        p[i].id=i;
        for(int j=1;j<=4;j++)
        {
            scanf("%d",&ls);
            p[i].sco+=ls;
        }
    }
    sort(p+1,p+1+n,cmp);
    for(int i=1;i<=n;i++) if(p[i].id==1) printf("%d\n",i);
    return 0;
}

相关链接:

Codeforces 题解小全:
https://blog.csdn.net/ZJ_MRZ/article/details/81530091

Codeforces 1016A Death Note 题解:
https://blog.csdn.net/ZJ_MRZ/article/details/81474520
.

转载于:https://www.cnblogs.com/zj-mrz/p/10122453.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值