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. vsCode--设置显示文件和搜索过滤

    文件位置:文件(File)-首选项(Preference)-设置(setting) 打开setting.json文件输入一下内容即可 { "search.exclude": { & ...

  2. 【每日Scrum】第八天冲刺

    一.计划会议内容 继续昨天的设计 二.任务看板 任务看板 已完成:登录与个人界面布局实现 进行中:UI设计美化,,地图主界面 待进行:功能整合,连接数据库 三.scrum讨论照片 四.产品的状态 无 ...

  3. 2014 3.22 校队选拔——A

    依然非常失望,我为什么现在还是那么弱,今天就做出了一道题,垫底. 一个大家都看出来的C题,我居然没找到规律,想了一会儿就放弃了. A题是这样的,有n种珍珠,给出这n种珍珠各自的数目,再给出一个M,表示 ...

  4. import datetime

    import datetimenow = datetime.datetime.now()print('当前时间:',now) 当前时间: 2019-11-21 11:11:58.093122

  5. [题解] 洛谷P3950 部落冲突

    传送门 拿到题目,一看 裸LCT (其实是我懒得打,splay又臭又长) 首先,这道题的意思就是删掉一些边 所以常规操作 点权转边权 之后对于战争操作,在对应的边上+1 对于和平操作,在对应的边上-1 ...

  6. Linux-常见信号介绍

    1.SIGINT           2 Ctrl + C时OS送给前台进程组中每个进程 2.SIGABRT             6              调用abort函数,进程异常终止 3 ...

  7. centos挂载磁盘

    Aliyun实例为例 简单操作: 查看磁盘情况:fdisk -l 对数据盘进行分区,一般类似/dev/vdb这种为数据盘 输入fdisk  /dev/vdb 对数据盘进行分区.根据提示,输入 n, p ...

  8. hdu1066 Last non-zero Digit in N!(求阶乘最后一位不为0的数字)

    http://acm.hdu.edu.cn/showproblem.php?pid=1066 转自:https://blog.csdn.net/fengyu0556/article/details/5 ...

  9. c# 异常处理 try --catch

    初学 try---catch 语法 try { 可能会出现异常的代码; 异常出现的那行代码下面的代码全不会执行,直接跳到catch中执行 ... ... } //try和catch之间不能有其他的代码 ...

  10. electron-builder打包跳过publish

    默认情况下执行 npm run release使用build命令打包时自动将打包好的安装程序发布到仓库,有时候不需要每次打包都上传到仓库,这时我们只需要在build命令后面加上参数-p never 即 ...