PAT 1036 Boys vs Girls
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm> using namespace std; class Stu {
public:
char name[];
char id[];
int grade;
char gender;
}; bool my_cmp(const Stu* a, const Stu* b) {
return a->grade < b->grade;
} void print (vector<Stu*> &stu) {
int len = stu.size();
for (int i=; i<len; i++) {
printf("%s %d\n", stu[i]->name, stu[i]->grade);
}
} int main() {
vector<Stu*> male;
vector<Stu*> female;
int n = ;
scanf("%d", &n); for (int i=; i<n; i++) {
Stu* p = new Stu();
scanf("%s %c %s %d", p->name, &(p->gender), p->id, &(p->grade)); if (p->gender == 'M') {
male.push_back(p);
} else {
female.push_back(p);
}
}
sort(male.begin(), male.end(), my_cmp);
sort(female.begin(), female.end(), my_cmp); Stu* best = NULL;
Stu* worst= NULL; if (female.empty()) {
printf("Absent\n");
} else {
best = female[female.size() - ];
printf("%s %s\n", best->name, best->id);
}
if (male.empty()) {
printf("Absent\n");
} else {
worst = male[];
printf("%s %s\n", worst->name, worst->id);
}
if (worst == NULL || best == NULL) {
printf("NA\n");
} else {
printf("%d", best->grade - worst->grade);
}
return ;
}
我感觉自己已经成脑残了,竟然忘了传my_cmp
PAT 1036 Boys vs Girls的更多相关文章
- 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分) 比大小而已
题目 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 ...
- 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 of ...
- 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 (25)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
随机推荐
- 未来it行业发展方向
https://www.zhihu.com/question/24222456 IT行业,未来10年和20年,技术发展方向会是什么? 本人CS 本科刚毕业,正在选择工作方向.希望之后专注一个方向发展. ...
- iis 重启命令
打开IIS配置窗口的CMD命令:开始---运行---CMD----输入inetmgr 直接使用CMD我们可以操作很多事情,比如启动IIS,重启IIS,停止IIS 重启IIS服务器,开始->运行 ...
- networkX如何读取存储图的二进制.dat文件
一般情况下,.dat文件存储的是图的二进制邻接矩阵. import networkx as nx G = nx.readadjlist('auth_graph.dat')
- Navicat Premium 12.1.12.0破解版激活
声明:本文所提供的所有软件均来自于互联网,个人存放在此作为备用,以备将来不时之需,同时作为大家的分享和学习成果,仅供个人研究和学习使用,请勿用于商业用途,下载后请于24小时内删除,请支持正版! 附:二 ...
- P2257 YY的GCD (莫比乌斯反演)
[题目链接] https://www.luogu.org/problemnew/show/P2257 // luogu-judger-enable-o2 /* -------------------- ...
- [BZOJ 3613][Heoi2014]南园满地堆轻絮
传送门 这题......注意读题就行 刚开始读成了Ans = Σ{|A[j]-B[j]|}以为是道神题,结果是Ans = Max{|A[j]-B[j]|}. 嗯.......可以证明Ans = 最大的 ...
- LightOJ - 1032 数位DP
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...
- cmd 打开mysql客户端
- n个骰子的和,组成数字m的可能
//n个骰子的和,组成数字m的可能 function f(n,m) { if(n==1){ return 1; } var len=m-n; var sum=0; while (len>=0){ ...
- scrapy模块之分页处理,post请求,cookies处理,请求传参
一.scrapy分页处理 1.分页处理 如上篇博客,初步使用了scrapy框架了,但是只能爬取一页,或者手动的把要爬取的网址手动添加到start_url中,太麻烦接下来介绍该如何去处理分页,手动发起分 ...