题意:

为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语。同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说,
在三个课程和平均成绩的四个职级中,我们打印每个学生的最佳排名。

例如,C,M,E和A - 4名学生的成绩如下:

StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
那么所有学生的最佳排名都是第一,因为第一名在C编程语言方面做得最好,而第二名则是数学第二名,英文第三名,平均第三名。

输入

每个输入文件包含一个测试用例。每个案例以包含2个数字N和M(<= 2000)的行开始,
分别是学生人数和学生人数。然后按N行,每个包含一个6位数字的学生ID,其后是C,M和E顺序的该学生的三个整数等级(在[0,100]范围内)。然后在那里是M行,每行包含学生ID

输出

对于每个M学生,以一行打印他/她的最佳排名,以及由空格分隔的相应排名的符号。

排名方法的优先级排序为A> C> M> E。因此,如果学生获得相同最佳排名有两种或更多种方式,则输出优先级最高的排名。
如果学生不在评分清单上,只需输出“N / A”即可。

思路:

1.我把ID设置成了String,实际上本来用int也是可以的。这就对判断M个字符串中是否之前又出现过造成了麻烦。对此,我一开始设置的node2结构体里,先给每个排名rank赋值为99999,顺便把字符串放队列里,然后再排序,再遍历队列,如果新来的字符串之前没有出现过,那么它的rank还将是99999,就输出N/A

2.排序弄得我头大,113336,而不是112223,也不是123456。首先本来sort里比较器>=就可以了,偏偏段错误。原因:https://blog.csdn.net/aichirourou_66/article/details/80928249

只好自己弄排序的名次,由此引入了k来存储上一个的名次。j=k,而不是M[a[i-1].s].rank,这个地方粗心损失了不少时间。

3.排序我居然重复写了四遍,实际上放在一个循环里就可以了。。。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n,m;
struct node{//存放学生信息
string s;
int c;
int ma;
int e;
double av;
}a[];
struct node2//存放rank信息
{
int rank;//排名
char course;//课程
node2(int _rank=,char _course='A')
{
rank=_rank;
course=_course;
}
};
map<string,node2>M;//将ID与rank信息一一对应
queue<string>Q; //用于放后面输入的M个字符串 bool cmp_av(const node &x, const node &y) {
return x.av > y.av;//不能>=,会段错误
}
bool cmp_c(const node &x, const node &y) {
return x.c > y.c;
}
bool cmp_ma(const node &x, const node &y) {
return x.ma > y.ma;
}
bool cmp_e(const node &x, const node &y) {
return x.e > y.e;
}
string ss;
int main()
{
cin>>n>>m;
while(!Q.empty()) Q.pop();
for(int i=;i<=n;i++){
cin>>a[i].s>>a[i].c>>a[i].ma>>a[i].e;
a[i].av=int((a[i].c+a[i].ma+a[i].e)*1.0/+0.5);
M[a[i].s]=node2(,'A');//先给个默认的rank信息
} for(int i=;i<=m;i++)
{
cin>>ss;
Q.push(ss);//先放进去,之后还要再遍历
M[a[i].s]=node2(,'A');//先给个默认的rank信息
}
sort(a+,a++n,cmp_av);
int k=;//为了名次设置的,113336,而不是112223,也不是123456
for(int i=;i<=n;i++)
{
int j=i;
if(i> && a[i].av==a[i-].av){
j=k;//为前面的名词
}
else{
k=j;//名词为j,同时更新k
}
if(M[a[i].s].rank>j){
M[a[i].s].rank=j;
M[a[i].s].course='A';
}
// cout<<j<<" "<<a[i].s<<" "<<a[i].av<<endl;
} sort(a+,a++n,cmp_c);
// cout<<endl;
k=;
for(int i=;i<=n;i++)
{
int j=i;
if(i> && a[i].c==a[i-].c){
j=k;
}
else{
k=j;
}
if(M[a[i].s].rank>j){
M[a[i].s].rank=j;
M[a[i].s].course='C';
}
// cout<<j<<" "<<a[i].s<<" "<<a[i].c<<endl;
} sort(a+,a++n,cmp_ma);
// cout<<endl;
k=;
for(int i=;i<=n;i++)
{
int j=i;
if(i> && a[i].ma==a[i-].ma){
j=k;
}
else{
k=j;
}
if(M[a[i].s].rank>j){
M[a[i].s].rank=j;
M[a[i].s].course='M';
}
// cout<<j<<" "<<a[i].s<<" "<<a[i].ma<<endl;
} sort(a+,a++n,cmp_e);
// cout<<endl;
k=;
for(int i=;i<=n;i++)
{
int j=i;
if(i> && a[i].e==a[i-].e){
j=k;
}
else{
k=j;
}
if(M[a[i].s].rank>j){
M[a[i].s].rank=j;
M[a[i].s].course='E';
}
// cout<<j<<" "<<a[i].s<<" "<<a[i].e<<endl;
}
while(!Q.empty())
{
ss = Q.front();
Q.pop();
//cout<<ss<<" "<<M[ss].rank<<endl;
if(M[ss].rank==){//不存在的情况
cout<<"N/A"<<endl;
}
else{
cout<<M[ss].rank<<" "<<M[ss].course<<endl;
}
}
return ;
}

PAT 甲级 1012 The Best Rank (25 分)(结构体排序)的更多相关文章

  1. PAT甲级1012. The Best Rank

    PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...

  2. 1012 The Best Rank (25分) vector与结构体排序

    1012 The Best Rank (25分)   To evaluate the performance of our first year CS majored students, we con ...

  3. PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  4. PAT 乙级 1085. PAT单位排行 (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-b-practise/1085 思路 结构体排序 要注意几个点 它的加权总分 是 取其整数部分 也就是 要 向下取整 然 ...

  5. 【PAT】1012. The Best Rank (25)

    题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...

  6. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  7. PAT 甲级 1056 Mice and Rice (25 分) (队列,读不懂题,读懂了一遍过)

    1056 Mice and Rice (25 分)   Mice and Rice is the name of a programming contest in which each program ...

  8. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  9. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

随机推荐

  1. Install RabbitMQ on CentOS 7

    NOTE: this article is only for CentOS 7 How to Install RabbitMQ on CentOS 7 yum update Install erlan ...

  2. Python多线程爬虫爬取网页图片

    临近期末考试,但是根本不想复习!啊啊啊啊啊啊啊!!!! 于是做了一个爬虫,网址为 https://yande.re,网页图片为动漫美图(图片带点颜色........宅男福利 github项目地址为:h ...

  3. HTTP通过Get请求传递参数时特殊字符被转码的处理方式

    有些符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了. 编码的格式为:%加字符的ASCII码,即一个百分号%,后面跟对应字符的ASCII(16进制)码值.例如 ...

  4. combogrid下拉方法封装

    //html <input id="addxxxxx" name="xxxxxx" style="width:380px;height:36px ...

  5. python3.6中 字典类型和字符串类型互相转换的方法

    mydic = {"俄罗斯": {"1":"圣彼得堡", "2":"叶卡捷琳堡", "3& ...

  6. C# 重写IComparer 接口

    首先定义比较类 继承自IComparer<Racer> public class RacerComparer : IComparer<Racer> { public enum ...

  7. Appium自动化测试教程-自学网-monkey简介

    Monkey简介 在Android的官方自动化测试领域有一只非常著名的“猴子”叫Monkey,这只“猴子”一旦启动,就会让被测的Android应用程序像猴子一样活蹦乱跳,到处乱跑.人们常用这只“猴子” ...

  8. Vivado RAM使用

    RAM使用的几点说明: 1,RAM的读写位宽可以不同,举例:写的位宽为8(1Byte),读的位宽为1(1bit),那么读的地址就变成了写地址的8倍,即位宽增加3bit.

  9. ES6-12.Symbol

    Symbol是ES6新增的原始类型数据,引入的初衷是为了对象可以有永不重复的属性名. 所以属性名可以是字符串外,还可以是Symbol值: const a = Symbol("a") ...

  10. [Luogu] 八数码难题

    https://www.luogu.org/problemnew/show/P1379 long long ago 暴力bfs #include <iostream> #include & ...