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 namegenderID 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 grade​F​​−grade​M​​. 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的更多相关文章

  1. PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  2. PAT 甲级 1036 Boys vs Girls(20)

    https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016 This time you are aske ...

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

  4. PAT甲级——A1036 Boys vs Girls

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  5. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  6. PAT 1036 Boys vs Girls[简单]

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  7. PAT 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分)   This time you are asked to tell the difference between the lowest grade ...

  8. 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

  9. 1036 Boys vs Girls (25分)(水)

    1036 Boys vs Girls (25分)   This time you are asked to tell the difference between the lowest grade o ...

随机推荐

  1. [SUCTF 2019]EasyWeb

    0x00 知识点 本题知识量巨大,把我给看傻了..盯着网上师傅们的博客看了好久.. 知识点1 构造不包含数字和字母的webshell 思路来自p牛 参考链接: https://www.leaveson ...

  2. 利用mysecureshell搭建sftp服务

    1.下载对应的mysecureshell-1.33-1.x86_64.rpm包 2.安装mysecureshell-1.33-1.x86_64.rpm 3.添加ftp用户 useradd ftp 4. ...

  3. 最短路问题--Floyd 畅通工程续

    畅通工程续 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很 ...

  4. Linux--Centos7开启关闭端口

    参考 http://blog.csdn.net/u013410747/article/details/61696178 查看已开放的端口(默认不开放任何端口)    firewall-cmd --li ...

  5. 踩一踩win7安装neo4j的坑

    本文使用zip解压方式安装,下载社区版zip 解压到喜欢的文件夹,然后配置环境变量NEO4J_HOME=D:\neo4j-community-3.5.5(自己的解压目录) 配置Path=%NEO4J_ ...

  6. phpExcel查询数据库导出excel表

    <?php         require_once 'PHPExcel.php';       require_once 'PHPExcel/Writer/Excel5.php';    re ...

  7. [CTSC2008]祭祀(二分图匹配)

    没有SPJ时显然是不需要输出方案的.不需要输出方案很好做,先把边扩展(因为会往下流),然后求最大独立集,最大独立集=n-最小点覆盖,因为其是最大独立集的补集.如何求最小点覆盖呢?毕竟我写过最大权闭合子 ...

  8. docker 一些简略环境搭建及部分链接

    1.center 7  搭建 docker https://www.cnblogs.com/yufeng218/p/8370670.html 2.docker 命令 https://www.cnblo ...

  9. oracle中带参存储过程的使用

    Oracle中存储过程带参分为:输入参数(in)和输出参数(out) 例如: create or replace procedure out_test(v_user in emp.user_name% ...

  10. JSONP 跨域问题

    JSONP跨域请求   什么是跨域: 1.域名不同 2.域名相同端口不同 js出于对安全考虑不支持跨域请求.我们可以使用JSONP解决跨域问题. 一.JSONP是什么 JSONP(JSON with ...