L2-027 名人堂与代金券


L2-027 名人堂与代金券


对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,总评成绩必须达到 60 分及以上,并且有另加福利:总评分在 [G, 100] 区间内者,可以得到 50 元 PAT 代金券;在 [60, G) 区间内者,可以得到 20 元PAT代金券。全国考点通用,一年有效。同时任课老师还会把总评成绩前 K 名的学生列入课程“名人堂”。本题就请你编写程序,帮助老师列出名人堂的学生,并统计一共发出了面值多少元的 PAT 代金券。

输入格式:
输入在第一行给出 3 个整数,分别是 N(不超过 10 000 的正整数,为学生总数)、G(在 (60,100) 区间内的整数,为题面中描述的代金券等级分界线)、K(不超过 100 且不超过 N 的正整数,为进入名人堂的最低名次)。接下来 N 行,每行给出一位学生的账号(长度不超过15位、不带空格的字符串)和总评成绩(区间 [0, 100] 内的整数),其间以空格分隔。题目保证没有重复的账号。

输出格式:
首先在一行中输出发出的 PAT 代金券的总面值。然后按总评成绩非升序输出进入名人堂的学生的名次、账号和成绩,其间以 1 个空格分隔。需要注意的是:成绩相同的学生享有并列的排名,排名并列时,按账号的字母序升序输出。

输入样例:

10 80 5
cy@zju.edu.cn 78
cy@pat-edu.com 87
1001@qq.com 65
uh-oh@163.com 96
test@126.com 39
anyone@qq.com 87
zoe@mit.edu 80
jack@ucla.edu 88
bob@cmu.edu 80
ken@163.com 70

输出样例:

360
1 uh-oh@163.com 96
2 jack@ucla.edu 88
3 anyone@qq.com 87
3 cy@pat-edu.com 87
5 bob@cmu.edu 80
5 zoe@mit.edu 80
/*
    L2-027 名人堂与代金券
    https://pintia.cn/problem-sets/994805046380707840/exam/problems/994805055176163328
*/

#include <cstring>
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct Student
{
    string email;
    int score;
    Student(){};
    Student(string e,int s):email(e),score(s){}

    bool operator<(Student& s)
    {
        if(this->score==s.score)
            return this->email<s.email;
        return this->score>s.score;
    }
};

int main()
{
    int numStudent,G,rank,totalPTA;
    scanf("%d %d %d",&numStudent,&G,&rank);
    vector<Student> students;
    for(int i=0;i<numStudent;i++)
    {
        Student student;
        cin>>student.email>>student.score;
        students.push_back(student);
        if(students[i].score>=60&&students[i].score<G)
            totalPTA+=20;
        if(students[i].score>=G&&students[i].score<=100)
            totalPTA+=50;
    }

    sort(students.begin(),students.end());

    int flag[numStudent];
    memset(flag, 0, sizeof(flag));
    flag[0]=1;
    for(int i=1;i<numStudent;i++)
    {
        if(students[i].score==students[i-1].score)
            flag[i]=flag[i-1];
        else 
            flag[i]=i+1;
    }

    printf("%d\n",totalPTA);
    for(int i=0;i<numStudent&&flag[i]<=rank;i++)
        cout<<flag[i]<<" "<<students[i].email<<" "<<students[i].score<<endl;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值