PAT甲级——1036 Boys vs Girls
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<cstdio>
#include<iostream>
using namespace std;
struct pNode{
char name[11];
char gender;
char ID[11];
int grade;
}temp,ans1,ans2;
int main()
{
ans1.grade=100;
ans2.grade=0;
bool malet=0,femalet=0,na=0;
int N;
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%s %s %s %d",temp.name,&temp.gender,temp.ID,&temp.grade);
if(temp.gender=='M')
{
if(temp.grade<ans1.grade)
{
ans1 = temp;
}
malet=true;
}
else if(temp.gender=='F')
{
if(temp.grade>ans2.grade)
{
ans2 = temp;
}
femalet=true;
}
}
if(femalet==true)
{
printf("%s %s\n",ans2.name,ans2.ID);
}
else
{
printf("Absent\n");
na=true;
}
if(malet==true)
{
printf("%s %s\n",ans1.name,ans1.ID);
}
else
{
printf("Absent\n");
na=true;
}
if(malet==true&&femalet==true)
{
printf("%d",ans2.grade-ans1.grade);
}
if(na==true)
{
printf("NA");
}
return 0;
}
PAT甲级——1036 Boys vs Girls的更多相关文章
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT 甲级 1036 Boys vs Girls(20)
https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016 This time you are aske ...
- PAT Advanced 1036 Boys vs Girls (25 分)
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PAT甲级——A1036 Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT 1036 Boys vs Girls[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
随机推荐
- mac安装浏览器同步测试工具
1.安装node.js (1)打开终端,输入以下命令安装Homebrew ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebre ...
- 题目(或游戏)流程控制器上传到GitHub
题目控制系统 1 支持 题目按相同的个数分组 2 支持 pause resume 3 支持 每题限定时间 4 支持 支持对计时器进行回调 5 支持 在全流程开始,全流程结束,每组开始,每组结束,每题开 ...
- [转]Log4j使用总结
Log4j使用总结 一.介绍 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务 器.NT的事件记录器. ...
- 池ThreadPoolExecutor使用简介
public static void main(String[] args) { //guava 创建线程池 //https://blog.csdn.net/chinabestchina/articl ...
- SQL基础教程(第2版)第3章 聚合与排序:练习题
存在以下 个错误. .使用了字符类型的列(product_name)作为 SUM 函数的参数. >> 解答 SUM 函数只能使用数值类型的列作为参数. . WHERE 子句写在了 GROU ...
- MLP神经网络 隐含层节点数的设置】如何设置神经网络隐藏层 的神经元个数
神经网络 隐含层节点数的设置]如何设置神经网络隐藏层 的神经元个数 置顶 2017年10月24日 14:25:07 开心果汁 阅读数:12968 版权声明:本文为博主原创文章,未经博主允许不得转 ...
- C#——发送邮件
需要2个引用 using System.Net;using System.Net.Mail; using (MailMessage mailMessige=new MailMessage()) usi ...
- 素小暖讲JVM:Eclipse运行速度调优
本系列是用来记录<深入理解Java虚拟机>这本书的读书笔记.方便自己查看,也方便大家查阅. 欲速则不达,欲达则欲速! 这两天看了JVM的内存优化,决定尝试一下,对Eclipse进行内存调优 ...
- mongodb的常见使用命令行
由于cms工程要连接mongodb所以需要在在cms服务端工程添加如下依赖:项目使用spring data mongodb操作mongodb数据库 <dependency> <gro ...
- IT架构的本质--阅读笔记01
万物都有其本质,也只有了解了事物的本质之后,才不至于出现在事物稍作改变时就难以应对的情况,作为软件工程专业的学生,我们应该对IT架构的本质有一定的了解.“老僧三十年前未参禅时,见山是山,见水是水.及至 ...