A1036. 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>
#include<string.h>
using namespace std;
typedef struct{
char name[];
char id[];
char gender;
int grade;
}info;
int main(){
int N, absent = ;
info boy, girl, temp;
boy.grade = ;
girl.grade = -;
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%s %c %s %d", temp.name, &(temp.gender), temp.id, &(temp.grade));
if(temp.gender == 'F'){
if(temp.grade > girl.grade){
girl = temp;
strcpy(girl.name, temp.name);
strcpy(girl.id, temp.id);
}
}else if(temp.gender == 'M'){
if(temp.grade < boy.grade){
boy = temp;
strcpy(boy.name, temp.name);
strcpy(boy.id, temp.id);
}
}
}
if(girl.grade == - || boy.grade == )
absent = ;
if(girl.grade == -)
printf("Absent\n");
else
printf("%s %s\n", girl.name, girl.id);
if(boy.grade == )
printf("Absent\n");
else
printf("%s %s\n", boy.name, boy.id);
if(absent == )
printf("NA\n");
else
printf("%d", girl.grade - boy.grade);
cin >> N;
return ;
}
总结:
1、与1006一样,信息排序模拟,使用struct 结构体记录信息项。尽量边读入边处理,不需要全部存储后再排序。
A1036. Boys vs Girls的更多相关文章
- PAT A1036 Boys vs Girls(25)
AC代码 #include <cstdio> #include <algorithm> using namespace std; const int max_n = 11000 ...
- PAT甲级——A1036 Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT1036:Boys vs Girls
1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...
- 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 ...
- 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
1036 Boys vs Girls This time you are asked to tell the difference between the lowest grade of all th ...
- 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上印象笔记的代码块
Mac 印象笔记左上角菜单栏:偏好设置-->软件更新-->开启代码块 (Preferences -> Software Update -> Enable code block) ...
- Windows 10 中 VMware 要求禁用 Device Guard 问题
今天在打开虚拟机的时候,突然出现下面这个错误.网上给了很多教程,基本上都是禁用 Device Guard 和关闭 Hyper-v,博主按照其方法操作,依旧出现下面错误.后来经过不懈努力,终于找到解决办 ...
- centos7下安装php+memcached简单记录
1)centos7下安装php 需要再添加一个yum源来安装php-fpm,可以使用webtatic(这个yum源对国内网络来说恐怕有些慢,当然你也可以选择其它的yum源) [root@nextclo ...
- ssh登陆服务器locale告警(-bash: warning: setlocale:)的处理方法
使用ssh远程登陆 IDC机房服务器,发现老是出现如下告警信息: -bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UT ...
- 1013 C. Photo of The Sky
传送门 [http://codeforces.com/contest/1013/problem/C] 题意 输入一个n代表n颗星星,输入2n个数,其中任意两个数代表一颗行星的坐标,问你把n个星星围起来 ...
- Visual Studio平台安装及测试
一.VS安装 图1.1 图1.2 二.单元测试练习 题目:课本22~25页单元测试练习 1.创建一个c#类(具体如下:打开VS2010,然后点击VS界面上左上角的文件按钮,然后点击文件—新建—项目,就 ...
- LINUX内核设计第五周——扒开系统调用的三层皮(下)
- JSON数据格式解析
JSON数据的语法规则 1.数据以键值对的形式 2.数据由逗号分隔 3.花括号保存对象 4.方括号保存数组 以PHP的数组为例: <?php $arr = array( "aaaa&q ...
- MySQLi面向对象实践--multi_query
使用multi_query可以实现执行多条SQL语句,每一条SQL语句通过分号分隔. 需要注意的是: 多条用分号分隔的SQL语句中,只要有一条SQL语句执行失败,那么这一条SQL语句以及之后的SQL语 ...
- Java 常用类的使用例子(整理)
可变字符序列——StringBuffer StringBuffer类和String类的方法几乎一样,不过StringBuffer对象表示的字符串是可以改变的,而String对象保存的字符串是不可变的. ...