1036. Boys vs Girls (25)

时间限制
400 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

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相关推荐

  1. PAT甲级1036 Boys vs Girls:[C++题解] 字符串处理

    文章目录 题目分析 题目链接 题目分析 分析可以看下方代码注释. ac代码 #include<bits/stdc++.h> using namespace std;int n; const ...

  2. A1036 Boys vs Girls 25分

    A1036 Boys vs Girls 25分 题目描述: 题目大意: 输入一个数N,以下N行每行输入一个学生信息,找到女生成绩最高的人和男生成绩最低的人,最后输出他们的名字.学号和成绩的差值. 思路 ...

  3. 1036. Boys vs Girls

    1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...

  4. 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 ...

  5. 【PAT甲级 排序】1036 Boys vs Girls (25 分) C++

    题目 是个水题,排序就完事. 输出女生最高分的学生,男生最低分的学生,并计算分差. 一点点小坑:让输出啥,看清楚再写,不要靠记忆做题 一开始把题目中要求输出的NA看成了NAN,一开始有两个测试用例过不 ...

  6. 1036 Boys vs Girls (25 分)_27行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 This time you are asked to tell the difference between the lowest ...

  7. 1036. Boys vs Girls (25)

    以分数为核心的事件模拟 #include<iostream> #include<vector>typedef struct Student {char name[20];cha ...

  8. 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 ...

  9. 1036 Boys vs Girls (25 分)

    题目链接 #include <iostream> using namespace std; int main() {int n;scanf("%d", &n); ...

最新文章

  1. tinybert华为
  2. 实践指南 | 用PyTea检测 PyTorch 中的张量形状错误
  3. 浅谈Linux的内存管理机制
  4. Android开发:Handler的简单使用(一)
  5. HDU 1513 Palindrome(最长公共子序列)
  6. el-table中设置fixed固定列之后错位的奇葩原因
  7. SAP Spartacus的Component 请求
  8. .NET 6 攻略大全(一)
  9. Java5泛型的用法,T.class的获取和为擦拭法站台
  10. 抽象类和接口的共同点和区别
  11. slf4j+logback 日志
  12. 不可错过!斯坦福课程3D数据的机器学习方法(Machine Learning for 3D Data)第二部分Geometry Foundations: Surface Representations
  13. 在Android Studio中使用Method trace,查看某进程的所有线程trace的方法
  14. javascript 实现页面加载完再显示页面
  15. 用Dim搭建轻量级媒体服务器
  16. 力扣438. 找到字符串中所有字母异位词 C++ (滑动窗口 + 数组)
  17. 用python把微信好友头像拼成一张图
  18. cocos creator android 真机调试配置密匙
  19. 利用mininet进行链路拥塞造成数据丢包的实验
  20. 打败你的不是现实,是时间管理|互联网时代的时间管理术

热门文章

  1. 自己写的Python数据库连接类和sql语句拼接方法
  2. ORACLE 体系结构知识总结
  3. 如何终止正在在发送的ajax请求
  4. 转: Android ListView 滑动背景为黑色的解决办法
  5. Python基础15-函数闭包与装饰器
  6. github创建静态页面_如何在10分钟内使用GitHub Pages创建免费的静态站点
  7. d3.js图表_如何使用D3.js建立历史价格图表
  8. 开源贡献 计算_如何克服恐惧并为开源做贡献
  9. (C++)1026 程序运行时间
  10. Python 第三方库自动安装脚本