PAT A1036 Boys vs Girls(25)
AC代码
#include <cstdio>
#include <algorithm>
using namespace std;
const int max_n = 11000;
struct Stu {
char name[20];
char gender;
char id[20];
char grade;
} boys_l, girls_h, temp;
void init() { //初始化,男生女生的成绩
//不能设置为100和0, 考虑边界值
boys_l.grade = 101;
girls_h.grade = -1;
}
int main() {
init();
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE}
int n, girls_num = 0, boys_num = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%s %c %s %d", temp.name, &temp.gender, temp.id, &temp.grade);
//printf("%s %c %s %d\n", temp.name, temp.gender, temp.id, temp.grade);
if(temp.gender == 'F') { //找出女生中成绩最高的且计算人数
girls_num++;
if(temp.grade > girls_h.grade) girls_h = temp;
}
if(temp.gender == 'M') {
boys_num++;
if(temp.grade < boys_l.grade) boys_l = temp;
}
}
/* printf("%s %s %d\n", girls_h.name, girls_h.id, girls_h.grade);
printf("%s %s %d\n", boys_l.name, boys_l.id, boys_l.grade);
printf("%d", girls_h.grade - boys_l.grade);
*/
if(boys_num&&girls_num) {
printf("%s %s\n", girls_h.name, girls_h.id);
printf("%s %s\n", boys_l.name, boys_l.id);
printf("%d", girls_h.grade - boys_l.grade);
} else if(boys_num == 0 && girls_num != 0) {
printf("%s %s\n", girls_h.name, girls_h.id);
printf("Absent\n");
printf("NA");
} else if(girls_num == 0 && boys_num != 0) {
printf("Absent\n");
printf("%s %s\n", boys_l.name, boys_l.id);
printf("NA");
} else {
printf("Absent\n");
printf("Absent\n");
printf("NA");
}
return 0;
}
PAT A1036 Boys vs Girls(25)的更多相关文章
- 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分) 比大小而已
题目 This time you are asked to tell the difference between the lowest grade of all the male students ...
- 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 (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 o ...
- 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)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
- PAT (Advanced Level) 1036. Boys vs Girls (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 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 ...
随机推荐
- D. Shortest Cycle(floyd最小环)
D. Shortest Cycle time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- PHP 二维数组去重方法
php二维数组的去重策略,如果需要根据某字段去重(其他字段可能不一致),那么需要使用循环策略,如果去重的都是相同的(字段,值),那么可以用序列化方式. $allComments = array_map ...
- Android 美团Robust热更新 使用入门
Android热更新方案Robust 相信很多人都认识了解过 热修复.热更新.热补丁(对于这个技术也没有特别标准的一种叫法,下面我统一叫热更新),之后的一年里,各种热更新方案如雨后春笋般出现,比较耳熟 ...
- Oracle 中的进制转换
Oracle 中的进制转换 */--> Oracle 中的进制转换 Table of Contents 1. 进制名 2. 10进制与16进制互相转换 2.1. 10进制转换为16进制 2.2. ...
- React Native 常用第三方组件
React-Native-Elements 一组开发RN的UI工具包(强烈推荐)
- 基于SAR对Linux资源的监控shell脚本
#! /bin/bash ] # $# 传递给脚本或函数的参数个数 then 脚本名称 exit -; fi SLEEP_TIME=$ LOG=$ while true do #线程数 thread_ ...
- RabbitMQ学习之:(十)AMQP和RabbitMQ介绍 (转贴+我的评论)
From: http://www.infoq.com/cn/articles/AMQP-RabbitMQ 准备开始 高级消息队列协议(AMQP1)是一个异步消息传递所使用的应用层协议规范.作为线路层协 ...
- 转 MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法
http://blog.sina.com.cn/s/blog_637e04c9010117ri.html 1 问题 [root@localhost mysql]# /etc/rc.d/init.d/m ...
- set_multicycle_path语法说明【转载】
(转载) (其实多看手册就知道原因了) Q:多周期路径中的检查保持时间时刻,为什么默认是在建立时间检查的前一个cycle?请大家谈谈自己的理解. 如:Set_multicycle_path -setu ...
- MongoDB 有关实体映射具体应用及对查询的影响
1 创建实体的时候,可以用注解@Document 对实体进行设置,指定集合名字 /** * */ package com.cfj.ceshi.entity; import org.springfram ...