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)的更多相关文章

  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 (25分) 比大小而已

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

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

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

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

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

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

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

  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)-找最大最小,大水题

    题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...

  8. PAT (Advanced Level) 1036. Boys vs Girls (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

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

随机推荐

  1. node中的koa2

    创建koa2工程 首先,我们创建一个目录hello-koa并作为工程目录用VS Code打开.然后,我们创建app.js,输入以下代码: // 导入koa,和koa 1.x不同,在koa2中,我们导入 ...

  2. 小程序和vue的区别

    最近开发了一个比较完整的小程序项目,打算总结一下,小程序开发和vue开发的代码上的区别 1.小程序的路由写在app.json文件里,vue写在route.js里 2.小程序用 src="{{ ...

  3. if-for-while

    if help if可以看看if的用法 if ls -l / ;then echo "ok";else echo "no" ;fi for for ((i=0; ...

  4. Configure vyatta

    Username: vyatta Password: vyatta 配置网卡: 编辑: configure 内部网络IP地址配置:192.168.0.1 set interfaces ethernet ...

  5. Qt 串口通信 高速发送出错的解决方法总结

    使用网上的qextserialport-1.2类,自行开发多线程串口通信.开发的过程中,出现两个问题:   问题1:我用信号槽跨线程调用串口类MyCom 发送和接收数据,中间运行的时候,会内存错误,Q ...

  6. SQL-W3School-基础:SQL 语法

    ylbtech-SQL-W3School-基础:SQL 语法 1.返回顶部 1. 数据库表 一个数据库通常包含一个或多个表.每个表由一个名字标识(例如“客户”或者“订单”).表包含带有数据的记录(行) ...

  7. matlab将字符串转化为变量的方法

    1.将字符串转化为变量的方法,执行 eval(x) 2.将变量转化为字符串的方法,执行 char(a) 讲解 aa = 98 x = 'aa' 目标:通过x得到98,即x->aa->98, ...

  8. Spring Security登录超时,angular ajax请求出错自动跳转至登录页(jQuery也适用)

    公司开发采用Spring Security+AngualerJS框架,在session过期之后,ajax请求会直接出错.本文介绍如何实现出错情况下自动跳转至登录页. 整体思路是,session过期后, ...

  9. AngularJS 指令(Directivce )一

    指令(Directive),是AngularJS中一块比较重要的内容,在实践中,我们提倡将控制器(Controller)写得短小精悍,逻辑代码尽量少,要实现这种目的,我们主要通过将逻辑代码抽取到服务( ...

  10. 使用AWS、Docker与Rancher提供弹性的生产级服务

    2017-07-26 开始想你的 RancherLabs AWS Summit 2017 Beijing已经圆满落幕啦!亚马逊公司首席技术官沃纳·威格尔博士莅临现场,分享 AWS 最新云解决方案,把握 ...