课本AC代码

#include <cstdio>

struct person {
char name[10];
int yy, mm, dd;
} oldest, youngest, left, right, temp; bool LessEqu(person a, person b) {
if(a.yy != b.yy) return a.yy <= b.yy;
else if(a.mm != b.mm) return a.mm <= b.mm;
else return a.dd <= b.dd;
} bool MoreEqu(person a, person b) {
if(a.yy != b.yy) return a.yy >= b.yy;
else if(a.mm != b.mm) return a.mm >= b.mm;
else return a.dd >= b.dd;
} void init() {
youngest.yy = left.yy = 1814;
oldest.yy = right.yy = 2014;
youngest.mm = oldest.mm = left.mm = right.mm = 9;
youngest.dd = oldest.dd = left.dd = right.dd = 6;
} int main() {
init();
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n, num = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%s %d/%d/%d", temp.name, &temp.yy, &temp.mm, &temp.dd);
int n = 0, m = 0;
if(MoreEqu(temp, left) && LessEqu(temp, right)) {
num++;
if(LessEqu(temp, oldest)) oldest = temp;
if(MoreEqu(temp, youngest)) youngest = temp;
}
}
if(num == 0) printf("0\n");
else printf("%d %s %s\n", num, oldest.name, youngest.name);
return 0;
}

自己的,两个没过

#include <cstdio>
#include <cstring> const int nowyear = 2014;
const int nowmonth = 9;
const int nowday = 6;
const int oldyear = 2014 - 200; struct People {
char name[50];
int year, month, day;
} temp, oldest, youngest, inleft, inright; bool right(People a, People b) { //判断出生日期是否比现在早
if(a.year == b.year) {
if(a.month == b.month) {
if(a.day == b.day) return true;
else return b.day > a.day;
} else return b.month > a.month;
} else return b.year > a.year;
} bool left(People a, People b) { //判断出生日期是否大于最早日期
if(a.year == b.year) {
if(a.month == b.month) {
if(a.day == b.day) return true;
else return a.day > b.day; //a.day - b.day;
} else return a.month > b.month; //a.month - b.month;
}else return a.year > b.year; //a.year - b.year;
}
bool judge(People a) { //判断日期是否合理
if(left(inright, a) && right(inleft, a)) return true;
else return false;
} void init() {
oldest.year = inright.year = nowyear;
youngest.year = inleft.year = nowyear - 200;
oldest.month = youngest.month = inright.month = inleft.month = nowmonth;
oldest.day = youngest.day = inright.month = inleft.day = nowday;
} int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
init();
int n; //生日的个数
int a = 0; //有效生日个数
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%s %d/%d/%d", temp.name, &temp.year, &temp.month, &temp.day);
//printf("%s %d/%d/%d\n", temp.name, temp.year, temp.month, temp.day);
int n = 0, m = 0;
// n = right()
if(judge(temp)) {
a++; //有效生日个数加1
if(right(youngest, temp)) youngest = temp;
if(left(oldest, temp)) oldest = temp;
//printf("youngest:%s oldest:%s\n", youngest.name, oldest.name);
}
}
if(a == 0) printf("0\n");
else printf("%d %s %s", a, oldest.name, youngest.name);
return 0;
}

PAT B1028 人口普查(20)的更多相关文章

  1. PAT 1028 人口普查(20)(STL-set+思路+测试点分析)

    1028 人口普查(20)(20 分) 某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的--假设已知镇上没有超 ...

  2. PAT 1028. 人口普查(20)

    某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的--假设已知镇上没有超过200岁的老人,而今天是2014年9月 ...

  3. PAT (Basic Level) Practise (中文)-1028. 人口普查(20)

    PAT (Basic Level) Practise (中文)-1028. 人口普查(20)   http://www.patest.cn/contests/pat-b-practise/1028 某 ...

  4. PAT乙级 1028. 人口普查(20)

    1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...

  5. PAT-乙级-1028. 人口普查(20)

    1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...

  6. PATB 1028. 人口普查(20)

    1028. 人口普查(20) 注意特判合理人数为0,否则格式错误.很暴力的sort排序找出最大最小. 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Stan ...

  7. PAT Basic 1028 人口普查 (20 分)

    某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,而今天是 2014 ...

  8. PAT 1028 人口普查

    https://pintia.cn/problem-sets/994805260223102976/problems/994805293282607104 某城镇进行人口普查,得到了全体居民的生日.现 ...

  9. PAT——1028. 人口普查

    某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而今天是2014年9月 ...

随机推荐

  1. 【CUDA 基础】5.0 共享内存和常量内存

    title: [CUDA 基础]5.0 共享内存和常量内存 categories: - CUDA - Freshman tags: - 共享内存 - 常量内存 toc: true date: 2018 ...

  2. XGBoost的优点

    1. Gradient boosting(GB) Gradient boosting的思想是迭代生多个(M个)弱的模型,然后将每个弱模型的预测结果相加,后面的模型Fm+1(x)基于前面学习模型的Fm( ...

  3. Django基础之Session

    1. Session的由来 Cookie虽然在一定程度上解决了“保持状态”的需求,但是由于Cookie本身最大支持4096字节,以及Cookie本身保存在客户端,可能被拦截或窃取,因此就需要有一种新的 ...

  4. LG5283 异或粽子

    题意 共有\(n\)个数,选择\(k\)个不同的\([l,r]\)区间,使得它们的异或和最大 $ 1 \leq n \leq 5 \times 10^5,k \leq 2 \times 10^5$ 思 ...

  5. delete elasticsearch

    在elasticsearch-head 插件中遇到的删除特定的数据需求 DELETE /索引名/需要清空的type/_query { "query": { "match_ ...

  6. RSA加密算法c++简单实现

    RSA是一种非对称加密算法,在公开密钥和电子商业中RSA被广泛使用.它是基于一个很简单的数论事实,两个素数相乘很容易,对两素数乘积因式分解很困难.原理就不再阐述了,我谈谈算法的编程实现过程. 一.RS ...

  7. dubbo服务层面上的负载均衡和高可用

    dubbo上的服务层可以做集群,来达到负载均衡和高可用,很简单,只需要在不同的服务器节点上向同一个zk(内网环境)注册相同的服务 注意就是,消费者不能在同一个zk做这种集群操作的 转载请注明博客出处: ...

  8. phpstorm clone 码云项目到本地 Version Control 不显示

    最近在用码云作为代码仓库,但是建了仓库,也填加了 SSH,把项目利用 phpstorm  VCS --> checkout from version control --> git 克隆到 ...

  9. rpm -qa|grep jdk

    转:http://blog.csdn.net/u012110719/article/details/42002221 RPM是RedHat Package Manager(RedHat软件包管理工具) ...

  10. 小D课堂 - 新版本微服务springcloud+Docker教程_5-08 断路器监控仪表参数

    笔记 8.断路器监控仪表参数讲解和模拟熔断     简介:讲解 断路器监控仪表盘参数和模拟熔断 1.sse  server-send-event推送到前端 资料:https://github.com/ ...