PAT1036:Boys vs Girls
1036. Boys vs Girls (25)
This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.
Input Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's name, gender, ID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.
Output Specification:
For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference gradeF-gradeM. If one such kind of student is missing, output "Absent" in the corresponding line, and output "NA" in the third line instead.
Sample Input 1:
3 Joe M Math990112 89 Mike M CS991301 100 Mary F EE990830 95
Sample Output 1:
Mary EE990830 Joe Math990112 6
Sample Input 2:
1 Jean M AA980920 60
Sample Output 2:
Absent Jean AA980920 NA 思路很简单,判断每次输入的是男是女,再比较下之前保存的成绩,分别保留女生最高和男生最低的成绩,最后计算下差值即可。有任何一方为空则按题要求输出对应的错误处理即可。代码
#include<iostream> #include<vector> #include<string> using namespace std;int main() {int N;while(cin >> N){vector<string> lowestmale(4);vector<string> highestfemale(4);string name,sex,subject,grade;for(int i = 0; i < N;i++){cin >> name >> sex >> subject >> grade;if(sex == "M"){if(lowestmale[3] == "" || (lowestmale[3] != "" && stoi(lowestmale[3]) > stoi(grade))){//如果是第一次输入或者这一次输入的成绩比以往更低lowestmale[0] = name;lowestmale[1] = sex;lowestmale[2] = subject;lowestmale[3] = grade;}}else{if(highestfemale[3] == "" || (highestfemale[3] != "" && stoi(highestfemale[3]) < stoi(grade))){//如果是第一次输入或者这一次输入的成绩比以往更高highestfemale[0] = name;highestfemale[1] = sex;highestfemale[2] = subject;highestfemale[3] = grade;}}}if(highestfemale[0] != "")cout << highestfemale[0] << " " <<highestfemale[2] << endl;elsecout << "Absent" << endl;if(lowestmale[0] != "")cout << lowestmale[0] << " " <<lowestmale[2] << endl;elsecout << "Absent" << endl;if(lowestmale[0] != "" && highestfemale[0] != "")cout << stoi(highestfemale[3]) - stoi(lowestmale[3]) << endl;elsecout << "NA" << endl;} }
转载于:https://www.cnblogs.com/0kk470/p/7623093.html
PAT1036:Boys vs Girls相关推荐
- PAT甲级1036 Boys vs Girls:[C++题解] 字符串处理
文章目录 题目分析 题目链接 题目分析 分析可以看下方代码注释. ac代码 #include<bits/stdc++.h> using namespace std;int n; const ...
- A1036 Boys vs Girls 25分
A1036 Boys vs Girls 25分 题目描述: 题目大意: 输入一个数N,以下N行每行输入一个学生信息,找到女生成绩最高的人和男生成绩最低的人,最后输出他们的名字.学号和成绩的差值. 思路 ...
- 1036. Boys vs Girls
1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...
- delphi word类型_现在的女生喜欢什么类型的男生?|What Kind of Boys Do Girls Like?
nán shēng dōu xiǎng chéng wéi nǚ shēng de lǐ xiǎng xíng 男生都想成为女生的理想型, dōu xiǎng huò dé nǚ shēng de x ...
- 【PAT甲级 排序】1036 Boys vs Girls (25 分) C++
题目 是个水题,排序就完事. 输出女生最高分的学生,男生最低分的学生,并计算分差. 一点点小坑:让输出啥,看清楚再写,不要靠记忆做题 一开始把题目中要求输出的NA看成了NAN,一开始有两个测试用例过不 ...
- 1036 Boys vs Girls (25 分)_27行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 This time you are asked to tell the difference between the lowest ...
- 1036. Boys vs Girls (25)
以分数为核心的事件模拟 #include<iostream> #include<vector>typedef struct Student {char name[20];cha ...
- Python-1036 Boys vs Girls
代码如下 N = int(input()) peo = [0 for _ in range(N+2)] for i in range(N):peo[i] = input().split(' ') ls ...
- 1036 Boys vs Girls (25 分)
题目链接 #include <iostream> using namespace std; int main() {int n;scanf("%d", &n); ...
最新文章
- tinybert华为
- 实践指南 | 用PyTea检测 PyTorch 中的张量形状错误
- 浅谈Linux的内存管理机制
- Android开发:Handler的简单使用(一)
- HDU 1513 Palindrome(最长公共子序列)
- el-table中设置fixed固定列之后错位的奇葩原因
- SAP Spartacus的Component 请求
- .NET 6 攻略大全(一)
- Java5泛型的用法,T.class的获取和为擦拭法站台
- 抽象类和接口的共同点和区别
- slf4j+logback 日志
- 不可错过!斯坦福课程3D数据的机器学习方法(Machine Learning for 3D Data)第二部分Geometry Foundations: Surface Representations
- 在Android Studio中使用Method trace,查看某进程的所有线程trace的方法
- javascript 实现页面加载完再显示页面
- 用Dim搭建轻量级媒体服务器
- 力扣438. 找到字符串中所有字母异位词 C++ (滑动窗口 + 数组)
- 用python把微信好友头像拼成一张图
- cocos creator android 真机调试配置密匙
- 利用mininet进行链路拥塞造成数据丢包的实验
- 打败你的不是现实,是时间管理|互联网时代的时间管理术