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 ...
随机推荐
- bash脚本中使用选项 getopts
原文链接 : http://note.youdao.com/noteshare?id=0cf08484c7308c763726e63e9a638ff5&sub=EF6A110E2F3345E6 ...
- Go Iris 中间件
Iris 中间件 当我们在 iris 中讨论中间件时,我们讨论的是在HTTP请求生命周期中在主处理程序代码之前和/或之后的运行代码. 实现中间件功能,有下面这样两种方式: 方式一: 我们可以通过按顺序 ...
- docker打包项目部署
1.首先在本地安装docker,步骤可参考https://www.cnblogs.com/conswin/p/11055853.html 2.在对应项目目录下增加Dockerfile文件,其内容可参考 ...
- Java-AQS源码详解(细节很多!)
ReentrantLock调用lock()时时序图: addWaiter方法: enq方法:自旋 它维护了一个volatile int state(代表共享资源)和一个FIFO线程等待队列(多线程争用 ...
- QString介绍
QString stores a string of 16-bit QChars, where each QChar corresponds one Unicode 4.0 character. 一. ...
- android data binding jetpack VII @BindingAdapter
android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...
- 11. Ingress及Ingress Controller(主nginx ingress controller)
11. Ingress,Ingress Controller拥有七层代理调度能力 什么是Ingress: Ingress是授权入站连接到达集群服务的规则集合 Ingress是一个Kubernetes资 ...
- [Python]使用pytest进行单元测试
安装pytest pipenv install pytest 验证安装的版本: pytest --version This , imported /site-packages/pytest.py 接下 ...
- 反射中的 Method 的 getReadMethod 与 getWriteMethod 使用 【获取一个对象的所有属性字段名称和其对应的值】
转: class反射(一),以及Method 的 getReadMethod 与 getWriteMethod 使用 2018年11月28日 17:27:42 zich77521 阅读数 788 ...
- mac被锁有pin码的解锁方法
停用规律: 错误5次密码停用1分钟 再错误3次停用5分钟 在错误1次就停用15分钟 再错误1次就是60分钟了,而且还没输入框了,这时候我们要通过按 option,commond这2个按钮来唤起输入框 ...