PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank
题意:
为了评估我们第一年的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”即可。
思路:
麻烦的地方就是排序了,我写的好丑。题意中排名方法的优先级排序为A> C> M> E 可以通过构造一个count[4]数组的方法来实现。只要当前下标下的数比后面的数都要小于或这等于就可以成立。
ac代码:
C++
// pat1012.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<unordered_map>
using namespace std;
struct stu {
string id;
int c;
int m;
int e;
int a;
char bestsub;
int best;
};
void getbest(vector<stu>& map)
{
char ans[4] = { 'A','C','M','E' };
int len = map.size();
for (int i = 0; i < len; i++)
{
//c = m = e = a = 1;
int count[4] = { 1,1,1,1 };
for (int j = 0; j < len; j++)
{
if (map[j].a > map[i].a)
{
count[0]++;
}
if (map[j].c > map[i].c)
{
count[1]++;
}
if (map[j].m > map[i].m)
{
count[2]++;
}
if (map[j].e > map[i].e)
{
count[3]++;
}
}
for (int k = 0; k < 4; k++)
{
int u = k + 1;
for (; u < 4; u++)
{
if (count[k] > count[u]) break;
}
if (u >= 4)
{
map[i].bestsub = ans[k];
map[i].best = count[k];
break;
}
}
}
}
int main()
{
int N, M,n;
cin >> N >> M;
n = N;
vector<stu> map;
while (N--)
{
stu s;
cin >> s.id >> s.c >> s.m >> s.e;
s.a = (s.c + s.m + s.e) / 3;
map.push_back(s);
}
getbest(map);
string tempid;
while (M--)
{
cin >> tempid;
int i = 0;
for (; i < n; i++)
{
if (map[i].id == tempid)
{
cout << map[i].best << " " << map[i].bestsub << endl;
break;
}
}
if (i >= n)
cout << "N/A" << endl;
}
return 0;
}
PAT甲级1012. The Best Rank的更多相关文章
- PAT 甲级 1012 The Best Rank
https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480 To evaluate the perfor ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- PAT甲级——1012 The Best Rank
PATA1012 The Best Rank To evaluate the performance of our first year CS majored students, we conside ...
- PAT——甲级1012:The Best Rank(有坑)
1012 The Best Rank (25 point(s)) To evaluate the performance of our first year CS majored students, ...
- 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 ...
- pat甲级1012
1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
- PAT甲级——A1012 The Best Rank
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单
题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...
随机推荐
- 【shell】shell编程总结
总结一下在写shell脚本时的常见注意事项: 1.shell脚本中的命令最好用命令的全路径,如果不知道全路径可以用which cmd查找命令的全路径. 2.shell脚本中定义环境变量用export ...
- 【zTree】zTree的3.5.26静态树与动态树(实用)
1.静态树: 目录结构:(css与js为下载的原文件夹)
- ahttp
# -*- coding: utf-8 -*- # @Time : 2018/8/20 14:35 # @Author : cxa # @File : chttp.py # @Software: Py ...
- 常用的Oracle的doc命令
常用的Oracle的doc命令 1.连接数据库 普通用户连接数据库: conn scott/tiger --(默认的用户名/密码).conn 即"connection"连接数据库的 ...
- php直接输出json格式
php直接输出json格式,很多新手有一个误区,以为用echo json_encode($data);这样就是输出json数据了,没错这样输出文本是json格式文本而不是json数据,正确的写法是应该 ...
- python继承问题
python构造函数:__init__(): 如果子类定义了自己的__init__构造方法函数,当子类的实例对象被创建时,子类只会执行自己的__init__方法函数,如果子类未定义自己的构造方法函数, ...
- 交通运输线(LCA)
题目大意: 战后有很多城市被严重破坏,我们需要重建城市.然而,有些建设材料只能在某些地方产生.因此,我们必须通过城市交通,来运送这些材料的城市.由于大部分道路已经在战争期间完全遭到破坏,可能有两个城市 ...
- ci框架hook钩子
<code>//启动hooks //app/config/config.php $config['enable_hooks'] = TRUE; //hooks配置 ///app/confi ...
- vim编码相关
与vim编码相关的四个配置: encoding:vim核心编码,所有vim交换区,信息提示区都用这个编码.打开文件的编码如果是其他编码,会自动转换为核心编码,保存时再转回文件编码. fileencod ...
- 【WPF】自定义控件之远程图片浏览
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...