课本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. node中的stream(流)内置模块

    stream是Node.js提供的又一个仅在服务区端可用的模块,目的是支持“流”这种数据结构. 什么是流?流是一种抽象的数据结构.想象水流,当在水管中流动时,就可以从某个地方(例如自来水厂)源源不断地 ...

  2. MySQL认识索引

    什么是索引? 索引在MySQL中也叫是一种“键”,是存储引擎用于快速找到记录的一种数据结构.索引对于良好的性能非常关键,尤其是当表中的数据量越来越大时,索引对于性能的影响愈发重要.索引优化应该是对查询 ...

  3. Django-内置的auth模块

    一.auth认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Django作为一个 ...

  4. Contos 安装Tomcat

    # 下载安装包 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.40/bin/apache-tomcat-8. ...

  5. 无线AP知识点

    FAT模式指该AP可以独立配置,有独立的管理界面,就像普通的无线AP:FAT模式主要用在没有使用AC的小型网络中. FIT模式指该AP由TP-LINK AC(无线控制器)统一管控设置.    1,这个 ...

  6. CodeForces–830B--模拟,树状数组||线段树

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. Liunx反弹shell的几种方式

    什么是反弹shell? 简单理解,通常是我们主动发起请求,去访问服务器(某个IP的某个端口),比如我们常访问的web服务器:http(https)://ip:80,这是因为在服务器上面开启了80端口的 ...

  8. springboot 配置跨越访问

    import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http.H ...

  9. Python——私有化 和 属性property

    Python——私有化 和 属性property 一.私有化 xx: 公有变量 _x: 单前置下划线,私有化属性或方法,from somemodule import *禁止导入,类对象和子类可以访问 ...

  10. springboot 获取控制器参数的几种方式

    这里介绍springboot 获取控制器参数有四种方式 1.无注解下获取参数 2.使用@RequestParam获取参数 3.传递数组 4.通过URL传递参数 无注解下获取参数无注解下获取参数,需要控 ...