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 ...
随机推荐
- Codeforces 1291A - Even But Not Even
题目大意: 给定一个字符串数字(很大) 问能不能删除一些数字(或者不删除) 使得剩余的数字各位数相加是偶数,但是这整个数字是个奇数 解题思路: 统计字符串中单个数字奇数的个数 分情况 个数为0或者1时 ...
- POJ 1502:MPI Maelstrom Dijkstra模板题
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6499 Accepted: 4036 Des ...
- C++ 操作数据库类
#pragma once #include <string> #include <windows.h> #include <algorithm> #include ...
- centos socket通信时 connect refused 主要是防火墙问题
centos socket通信时 connect refused 主要是防火墙问题,可以关闭防火墙,或者开放程序中的端口
- ES6 之 数组的扩展
ES5 检测数组 let arr = [1,2,3,4] Array.isArray(arr) arr instanceof Array 转换方法 arr.toLocaleString() arr.t ...
- Codeforces 405D 数学问题
真是脑残...擦 具体题解在这里 http://www.cnblogs.com/windysai/p/3619222.html 原本我为了防止两个数冲突,设置了好多判断,结果发现,如果两个数冲突,另外 ...
- C# 创建Windows服务。服务功能:定时操作数据库
一.创建window服务 1.新建项目-->选择Windows服务.默认生成文件包括Program.cs,Service1.cs 2.在Service1.cs添加如下代码: System.T ...
- idea 2018.3.4 破解
我的idea_home=C:\Program Files\\IntelliJ IDEA 2018.3.4\ 1.下载破解文件 链接:https://pan.baidu.com/s/1I2APmk-pj ...
- Django模型基础(三)——关系表的数据操作
模型之间可以有三种表关系,即一对一,一对多和多对多.表关联之间的数据操作在Django中可以很方便的操作到.在模型中,表关联的字段类型是关联表的实例,而不是字段本身类型.关联字段在数据库中会在其后补上 ...
- Python笔记_第四篇_高阶编程_进程、线程、协程_4.协程
1.协程的概念: 子程序或者子函数,在所有语言中都是层级调用,比如A调用B,再B执行的过程中又可以调用C,C执行完毕返回,B执行返回,最后是A执行完毕返回.是通过栈来实现的,一个线程就是执行一个自称, ...