博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pat1012. The Best Rank (25)
阅读量:5042 次
发布时间:2019-06-12

本文共 4711 字,大约阅读时间需要 15 分钟。

1012. The Best Rank (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID  C  M  E  A310101     98 85 88 90310102     70 95 88 84310103     82 87 94 88310104     91 91 91 91

Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output "N/A".

Sample Input
5 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999
Sample Output
1 C1 M1 E1 A3 AN/A

   

 

注意点:

1.题目先给出n个学生的情况,先对这n个学生按照A、C、M、E的顺序依次进行排序,按照题意得到每个学生最好的排名情况,存储下来。然后,查询m个学生,如果学生不存在,则输出“N/A”,否则,输出最好排名及对应A、C、M、E的哪种情况。

2.题目中如果排名是1 2 2 4 5 6 6 8规则排名(见代码),却不是1 2 2 3 4 5 5 6 

3.map的使用:

 

添加元素:

map<int ,string> maplive;  

1)maplive.insert(pair<int,string>(102,"aclive"));

2)maplive.insert(map<int,string>::value_type(321,"hai"));
3)maplive[112]="April";                      //map中最简单最常用的插入添加!

 

查找元素:

find()函数返回一个迭代器指向键值为key的元素,如果没找到就返回指向map尾部的迭代器。        

map<int ,string >::iterator l_it;; 

l_it=maplive.find(112);
if(l_it==maplive.end())
                cout<<"we do not find 112"<<endl;
else cout<<"wo find 112"<<endl;

 

删除元素:

map<int ,string >::iterator l_it;

l_it=maplive.find(112);
if(l_it==maplive.end())
        cout<<"we do not find 112"<<endl;
else  maplive.erase(l_it);    //删除元素

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std; 10 struct cnode{ 11 int grade; 12 string id; 13 }; 14 struct mnode{ 15 int grade; 16 string id; 17 }; 18 struct enode{ 19 int grade; 20 string id; 21 }; 22 struct anode{ 23 int grade; 24 string id; 25 }; 26 struct somenode{ 27 int rank; 28 string r; 29 }; 30 map
some; 31 bool cmpa(anode a,anode b){ 32 return a.grade>b.grade; 33 } 34 bool cmpc(cnode a,cnode b){ 35 return a.grade>b.grade; 36 } 37 bool cmpm(mnode a,mnode b){ 38 return a.grade>b.grade; 39 } 40 bool cmpe(enode a,enode b){ 41 return a.grade>b.grade; 42 } 43 int main(){ 44 //freopen("D:\\INPUT.txt","r",stdin); 45 int n,m,cg,mg,eg; 46 string num; 47 scanf("%d %d",&n,&m); 48 anode *ap=new anode[n]; 49 cnode *cp=new cnode[n]; 50 mnode *mp=new mnode[n]; 51 enode *ep=new enode[n]; 52 int i; 53 for(i=0;i
>num; 55 scanf("%d %d %d",&cg,&mg,&eg); 56 ap[i].id=ep[i].id=cp[i].id=mp[i].id=num; 57 ap[i].grade=int((cg+mg+eg)*1.0/3+0.5); //四舍五入 58 ep[i].grade=eg; 59 mp[i].grade=mg; 60 cp[i].grade=cg; 61 } 62 63 64 sort(ap,ap+n,cmpa); 65 int cal=1; 66 somenode p; 67 p.r="A"; 68 p.rank=cal; 69 some[ap[0].id]=p; 70 for(i=1;i
cal){ 83 some[cp[0].id].rank=cal; 84 some[cp[0].id].r="C"; 85 } 86 for(i=1;i
cal){ 91 some[cp[i].id].rank=cal; 92 some[cp[i].id].r="C"; 93 } 94 } 95 96 97 sort(mp,mp+n,cmpm); 98 cal=1; 99 if(some[mp[0].id].rank>cal){100 some[mp[0].id].rank=cal;101 some[mp[0].id].r="M";102 }103 for(i=1;i
cal){108 some[mp[i].id].rank=cal;109 some[mp[i].id].r="M";110 }111 }112 113 114 sort(ep,ep+n,cmpe);115 cal=1;116 if(some[ep[0].id].rank>cal){117 some[ep[0].id].rank=cal;118 some[ep[0].id].r="E";119 }120 for(i=1;i
cal){125 some[ep[i].id].rank=cal;126 some[ep[i].id].r="E";127 }128 }129 130 131 map
::iterator it;132 for(i=0;i
>num;134 it=some.find(num);135 if(it==some.end()){136 cout<<"N/A"<

 

转载于:https://www.cnblogs.com/Deribs4/p/4703113.html

你可能感兴趣的文章
UI_搭建MVC
查看>>
一个样例看清楚JQuery子元素选择器children()和find()的差别
查看>>
代码实现导航栏分割线
查看>>
Windows Phone开发(7):当好总舵主 转:http://blog.csdn.net/tcjiaan/article/details/7281421...
查看>>
ASP.Net页面和控件缓存设置
查看>>
SEO第一步做什么
查看>>
Python-01作业(登录和三级菜单)
查看>>
spring-qualifier解释
查看>>
URL参数中文乱码解决
查看>>
VS 2010打开设计器出现错误
查看>>
SQLServer 镜像功能完全实现
查看>>
Vue-详解设置路由导航的两种方法
查看>>
一个mysql主从复制的配置案例
查看>>
大数据学习系列(8)-- WordCount+Block+Split+Shuffle+Map+Reduce技术详解
查看>>
dvwa网络渗透测试环境的搭建
查看>>
Win8 安装VS2012 和 Sql Server失败问题
查看>>
过点(2,4)作一直线在第一象限与两轴围成三角形,问三角形面积的最小值?...
查看>>
java aes CBC的填充方式发现
查看>>
使用ionic cordova build android --release --prod命令打包报有如下错误及解决方法
查看>>
BZOJ 2338 HNOI2011 数矩形 计算几何
查看>>