题意:

为了评估我们第一年的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下内存检测工具

    1.Intel的Parallel Inspector工具,和vs集成超好, 而且还带了线程检测工具. 2.Purifyhttps://www.cnblogs.com/hehehaha/archive/ ...

  2. CentOS7主机SSH连接失败

    说来话长,之前20刀一年买bandwagon的廉价VPS,由于做了一些违法的事情,导致ip被封了. 检测ip被封的方法:进入ping.chinaz.com:输入IP地址,如果国外节点能够Ping通而国 ...

  3. 日常note

    1.插入使相同的最少次数 给定两个序列A,B 每次只能进行把一个元素插入特定位置的操作 求至少对A进行多少次才能使A等于B 设A,B的长度为Len,那么答案为 \(Len-LCS(A,B)\) 2.\ ...

  4. 将vim打造成python开发工具

    1.创建vim插件工作目录 [root@ray ~]# mkdir -p ~/.vim/bundle 2.下载插件 [root@ray ~]# cd ~/.vim/bundle [root@ray b ...

  5. Strategic game POJ - 1463 【最小点覆盖集】

    Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu ...

  6. [git]本地分支关联远程仓库

    远程仓库中分支存在 方法一:(已经创建了本地分支) git branch --set-upstream-to=origin/remote_branch your_branch //等同于 git br ...

  7. python define function

    >>> def square(x): ... 'calculates the square of the number x.' ... return x*x ... >> ...

  8. netstat 基本用法

    Netstat 是一款命令行工具,可用于列出系统上所有的网络套接字连接情况,包括 tcp, udp 以及 unix 套接字,另外它还能列出处于监听状态(即等待接入请求)的套接字.如果你想确认系统上的 ...

  9. [Luogu] 可持久化线段树 1(主席树)

    https://www.luogu.org/problemnew/show/P3834 #include<cstdio> #include<iostream> #include ...

  10. Codeforces.520B.Two Buttons(正难则反)

    题目链接 \(Description\) 给定两个数\(n,m\),每次可以使\(n\)减一或使\(n\)乘2.求最少需要多少次可以使\(n\)等于\(m\). \(Solution\) 暴力连边BF ...