课本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. Django-cookie-sesson

    一 会话跟踪 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话,你就是客户端,而10086服务人员就是服务器 ...

  2. Codeforces 869E. The Untended Antiquity (二维Fenwick,Hash)

    Codeforces 869E. The Untended Antiquity 题意: 在一张mxn的格子纸上,进行q次操作: 1,指定一个矩形将它用栅栏围起来. 2,撤掉一个已有的栅栏. 3,询问指 ...

  3. HDU 4496 D-City —— (并查集的应用)

    给出n个点和m条边,一条一条地删除边,问每次删除以后有多少个联通块. 分析:其实就是并查集的应用,只是前一阵子一直做图论思路一直囿于tarjan了..方法就是,记录每一条边,然后从最后一条边开始不断的 ...

  4. mysql 1045 - Access denied for user 'root'@'*.*.*.*' (using password YES)

    远程无法连接mysql 解决方法: 1.在服务器登录数据 mysql -uroot -hlocalhost -P3306 -p Enter password: Welcome to the MySQL ...

  5. crobtab

    在使用node-cron包,作者在issue建议使用 https://crontab.guru/ 测试使用定时任务 发现一个问题 https://crontab.guru/#0_23_11-12,18 ...

  6. css实现元素在div底部显示

    #CSS .1 {position:relative;} .2 {;} #HTML <div class="1"> <div class="2" ...

  7. Process.Net

    ProcessSharp的构造函数,对应的测试是 https://github.com/lolp1/Process.NET/blob/master/test/Process.NET.Test/Core ...

  8. sentinel控制台监控数据持久化【InfluxDB】

    根据官方wiki文档,sentinel控制台的实时监控数据,默认仅存储 5 分钟以内的数据.如需持久化,需要定制实现相关接口. https://github.com/alibaba/Sentinel/ ...

  9. Oracle 报错 ORA-03290的处置

    MySql 的tuancate命令是直接truncate tableName,但在Oracle需要写成truncate table tableName,改正就好了. --END-- 2019.10.1 ...

  10. linux下如何找出交叉编译器的某个库路径?

    答: 使用选项-print-file-name=<lib_name> 如列出libstdc++.so.6的库路径:aarch64-linux-gnu-gcc -print-file-nam ...