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 ...
随机推荐
- 使用html画爱心
<!DOCTYPE html"> <html> <head> <meta http-equiv="Content-Type" c ...
- AJAX(阿贾克斯)的简单应用
1.ajax 对象的属性说明(常用的) (1)open(method,url,boolean);创建请求,method :填请求类型(get post),url :请求的地址, boolean:tru ...
- MySQL的DDL和DML
SQL语句:结构化查询语句,使用SQL与数据库“沟通”,完成相应的数据库操作. 语句分类 DDL(Data Definition Languages)语句:即数据库定义语句,用来创建数据库中的表.索引 ...
- 牛逼了,用Python破解wifi密码
Python真的是无所不能,原因就是因为Python有数目庞大的库,无数的现成的轮子,让你做很多很多应用都非常方便.wifi跟我们的生活息息相关,无处不在.今天从WiFi连接的原理,再结合代码为大家详 ...
- Memcached做Tomcat的session共享
基于cache DB缓存的session共享 基于memcache/redis缓存的session共享.即使用cacheDB存取session信息,应用服务器接受新请求将session信息保存在cac ...
- preg_match()//explode()// 输出函数//assert()//trim()
1.preg_match() 这是一个正则表达式匹配的函数,其用法如下: 查找文本字符串"php": <?php //模式分隔符后的"i"标记这是一个大小 ...
- C++queue的使用
C++队列是一种容器适配器,提供了一种先进先出的数据结构. 队列(queue)模板类定义在<queue>头文件中 基本操作: 定义一个queue变量:queue<Type> q ...
- Fidder IOS抓包
Fiddler-HTTPS配置 手机抓包配置 手机网络配置 打开Safari浏览器输入IP+端口号:192.168.0.14:8888,安装证书 证书信任设置:通用 - 关于本机 - 证书信任设置 - ...
- 题解【[HAOI2006]受欢迎的牛】
切水题,写题解~ tarjan缩一波点,然后 只有一个出度为0的点:他的size就是答案 有多个初度为0的点:无解,0个 因为是强联通分量,所以肯定有出度为0的点,否则--就是你tarjan写挂了~ ...
- bzoj4311向量(线段树分治+斜率优化)
第二道线段树分治. 首先设当前向量是(x,y),剩余有两个不同的向量(u1,v1)(u2,v2),假设u1>u2,则移项可得,若(u1,v1)优于(u2,v2),则-x/y>(v1-v2) ...