题意:

为了评估我们第一年的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. Windows Media Player播放视频导致程序闪退

    在有的电脑上发现,使用Windows Media Player组件播放视频导致程序闪退. 发现是显卡问题,独立显卡换成集成显卡 解决: 打开显卡控制面板->管理3D设置->集成图形-> ...

  2. 如何实现UI自动化?DevExpress Winforms帮你忙

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...

  3. idea maven配置

    转载自:https://www.cnblogs.com/Silencepeng/p/7444012.html 一.下载maven的包 http://www.apache.org/ 1.在网页中打开上面 ...

  4. 2 使用unitest 模块扩展功能测试

    准备做一个 待办事项清单网站,来演示 Web 开发过程中的所有主要步骤.以及如何在各个步骤中运用TDD理念. ”功能测试“: 从用户的角度查看应用是如何运作的. 从某种程度上可以作为应用的说明书. 作 ...

  5. 005_FreeRTOS任务挂起和恢复

    (一) (二)使用,参数是任务句柄 //key任务函数 void key_task(void *pvParameters) { u8 key; ) { key=KEY_Scan(); switch(k ...

  6. linux认识

    linux基础 根目录 文档扩展名 在Linux中,跟windows的扩展名.exe .bat.dll不同,只要在那十个字符中有x权限,这个档案就是可执行的, 但是,可被执行和执行成功是两回事,在Li ...

  7. access函数

    access函数是按照实际用户ID和实际组ID进行访问测试的.函数的定义如下: #include <unistd.h> int access(const char* pathname, i ...

  8. Linux进程通信之mmap

    mmap()函数: void *mmap(void* addr,size_t length,int port,int flags,int fd,off_t offset); 返回:成功:返回创建的映射 ...

  9. Java三大特征--多态

    1.定义 允许不同类的对象对同一消息做出响应,即同一消息可以根据发送对象的不同而采用多种不同的行为方式. 2.存在条件 2.1存在继承关系 2.2子类重写了父类方法 2.3父类类型的变量指向子类对象的 ...

  10. JavaWeb_(SpringMVC框架)SpringMVC&Spring&MyBatis整合

    JavaWeb_(SpringMVC框架)测试SpringMVC&Spring&MyBatis三大整合 传送门 1.整合ssm 3大框架 过程 a)导包 -> spring_Ja ...