当前位置:网站首页>Pat class A - 1012 the best rank (PIT)
Pat class A - 1012 the best rank (PIT)
2022-06-23 01:21:00 【S atur】
The question : Each student has his own serial number id, as well as C Language scene c, Math scores m, English scores e, And the average a. The title will output n Of a student id And three major subjects , Climate tracking m Time to ask , Ask someone id Students' best grades ranking and subject name .
Ideas : The idea is very simple , Divide into four arrays to store the scores of all students in each subject, and then arrange them in order . But two pits need to be noticed :1. The highest ranking of students must be selected according to a,c,m,e The priority of is the highest ranked account ( That is, each score is ranked third , But you must output 3 A).2. The same scores rank the same , But the next score will not be added up ( That is to say, now there is 90、90、89 Three achievements , The ranking of Qi is 1、1、3).
AC Code :
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5+10;
int n, m;
struct node{
int c, m, e, a;
};
map<string, node> mp;
vector<node> cc, mm, ee, aa;
map<int, int> gc, gm, ge, ga;
map<string, int> vis;
bool cmpc(node x, node y){
return x.c>y.c;
}
bool cmpm(node x, node y){
return x.m>y.m;
}
bool cmpe(node x, node y){
return x.e>y.e;
}
bool cmpa(node x, node y){
return x.a>y.a;
}
signed main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++){
string s; int x, y, z;
cin >> s >> x >> y >> z;
vis[s] = 1;
node tmp = {x, y, z, (x+y+z)/3};
mp[s] = tmp;
cc.push_back(tmp);
mm.push_back(tmp);
ee.push_back(tmp);
aa.push_back(tmp);
}
sort(cc.begin(), cc.end(), cmpc);
sort(mm.begin(), mm.end(), cmpm);
sort(ee.begin(), ee.end(), cmpe);
sort(aa.begin(), aa.end(), cmpa);
for(int i = 0; i < cc.size(); i ++){
if(!gc[cc[i].c]) gc[cc[i].c] = i+1;
}
for(int i = 0; i < mm.size(); i ++){
if(!gm[mm[i].m]) gm[mm[i].m] = i+1;
}
for(int i = 0; i < ee.size(); i ++){
if(!ge[ee[i].e]) ge[ee[i].e] = i+1;
}
for(int i = 0; i < aa.size(); i ++){
if(!ga[aa[i].a]) ga[aa[i].a] = i+1;
}
while(m--){
string s;
cin >> s;
if(!vis[s]){
cout << "N/A" << endl;
continue;
}
int pc = gc[mp[s].c], pm = gm[mp[s].m], pe = ge[mp[s].e], pa = ga[mp[s].a];
if(pa<=pc&&pa<=pm&&pa<=pe) cout << pa << " A" << endl;
else if(pc<=pm&&pc<=pe&&pc<=pa) cout << pc << " C" << endl;
else if(pm<=pc&&pm<=pe&&pm<=pa) cout << pm << " M" << endl;
else if(pe<=pc&&pe<=pm&&pe<=pa) cout << pe << " E" << endl;
// cout << mp[s].c << " " << mp[s].m << " " << mp[s].e << " " << mp[s].a << endl;
// cout << pc << " " << pm << " " << pe << " " << pa << endl << endl;
}
return 0;
}
边栏推荐
- [sliding window] leetcode992 Subarrays with K Different Integers
- 一文读懂基于Redis的Amazon MemoryDB数据库
- 07 project cost management
- Vector 1 (classes and objects)
- Real topic of the 2020 Landbridge cup provincial competition - go square (dp/dfs)
- C language student achievement ranking system
- Template specialization template <>
- Swiftui swift tutorial 14 useful array operators
- 魔王冷饭||#099 魔王说西游;老板的本质;再答中年危机;专业选择
- E-R图
猜你喜欢

SAP mm transaction code vl04 create outbound delivery for sto

Installation record of ros1noetic in Win 11

贵金属现货白银如何呢?

一文读懂基于Redis的Amazon MemoryDB数据库

SAP ui5 application development tutorial 102 - detailed explanation of the print function of SAP ui5 applications

LeetCode 206. Reverse linked list (iteration + recursion)

3DMAX modeling notes (I): introducing 3DMAX and creating the first model Hello World

New progress in the construction of meituan's Flink based real-time data warehouse platform

Development status of full color LED display

崔鹏团队:万字长文梳理「稳定学习」全景图
随机推荐
人民币的单位的大写
Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
three. JS simulated driving tour art exhibition hall - creating super camera controller
Cadence spb17.4 - Allegro - optimiser la spécification de l'angle de connexion de la polyligne pour une seule ligne électrique - polyligne à arc
崔鹏团队:万字长文梳理「稳定学习」全景图
Hello, is the securities account presented by the Business School of qiniu business school safe? How can I open a safe stock account to speculate in stocks
62. different paths
How to get started with machine learning?
How about China International Futures Co., Ltd.? Is it a regular futures company? Is it safe to open an account online?
Is it safe to open a new bond? How
Software construction course ADT and OOP understanding
SAP ui5 application development tutorial 103 - how to consume the trial version of the third-party library in SAP ui5 applications
Flowable global listener monitors the start and end of a process
[launch] redis Series 2: data persistence to improve availability
Big guys, 2.2.1 the CDC monitoring SQLSEVER can only get the full amount of data. Why can't we get the incremental data in the later period
层次选择器
Binary tree to string and string to binary tree
cadence SPB17.4 - allegro - 优化指定单条电气线折线连接角度 - 折线转圆弧
Shell 查看帮助
LINQ 查询