PAT B1028 人口普查(20)
课本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)的更多相关文章
- PAT 1028 人口普查(20)(STL-set+思路+测试点分析)
1028 人口普查(20)(20 分) 某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的--假设已知镇上没有超 ...
- PAT 1028. 人口普查(20)
某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的--假设已知镇上没有超过200岁的老人,而今天是2014年9月 ...
- PAT (Basic Level) Practise (中文)-1028. 人口普查(20)
PAT (Basic Level) Practise (中文)-1028. 人口普查(20) http://www.patest.cn/contests/pat-b-practise/1028 某 ...
- PAT乙级 1028. 人口普查(20)
1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...
- PAT-乙级-1028. 人口普查(20)
1028. 人口普查(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 某城镇进行人口普查,得到了全体居民的 ...
- PATB 1028. 人口普查(20)
1028. 人口普查(20) 注意特判合理人数为0,否则格式错误.很暴力的sort排序找出最大最小. 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Stan ...
- PAT Basic 1028 人口普查 (20 分)
某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,而今天是 2014 ...
- PAT 1028 人口普查
https://pintia.cn/problem-sets/994805260223102976/problems/994805293282607104 某城镇进行人口普查,得到了全体居民的生日.现 ...
- PAT——1028. 人口普查
某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而今天是2014年9月 ...
随机推荐
- Mac下Eclipse(Oxygen)添加Tomcat插件
1 查看本机Tomcat版本 ~$ sh /Library/Tomcat/bin/catalina.sh version SiegdeMacBook-Pro:bin Sieg$ sh /Library ...
- NSObject和反射
如何NSObject和反射 NSObject 常用方法 如何判断 某个对象是否属于某个类或子类 -(BOOL)isKindOfClass:(Class)aClass 判断是否为aClass的实例(不包 ...
- PHP开发框架CI——学习小记
之前做后端开发的时候,因为都是很小的功能或项目,所以基本都是手写原生php.不过这样的开发效率在面对稍大一些的项目的时候是比较低的.因此花时间学习一下php相关框架CI的使用. MVC架构 在学习CI ...
- linux磁盘内存满了?删除大文件依然不起作用
好久没有更新博客了,但并不代表自己没有遇到技术问题了.遇到了一大堆,也解决了一大堆.只是没有记下来的欲望了,似乎大脑就这样,忘不掉.啥都忘不掉了,即使忘掉了也知道如何百度了. 查看目录大小命令 du命 ...
- 一些风骚的shell命令行操作
1.用你最喜欢的编辑器来敲命令 command <CTRL-x CTRL-e> 在已经敲完的命令后按<CTRL-x CTRL-e>,会打开一个你指定的编辑器(比如vim,通过环 ...
- shell 里的正则
#!/bin/bash variable="This is a fine mess." echo "$variable" # Regex matching wi ...
- Beta冲刺(2/5)
队名:new game 组长博客 作业博客 组员情况 鲍子涵(队长) 过去两天完成了哪些任务 验收游戏素材 学习Unity 2D Animation系统 基本做完了人物的各个动画 接下来的计划 冲击E ...
- HearthBuddy BotManager
MainWindow private void button_0_Click(object sender, RoutedEventArgs e) { Configuration.Instance.Sa ...
- shell远程操作另外一台机器上数据
shell远程操作另外一台机器上的数据,有两种方式: 1 .配置免密登陆,2.使用sshpass 当前存在两台虚拟机,ip地址分别为:192.168.3.32 192.168.3.33 一.免密登陆操 ...
- 【8583】ISO8583报文解析
ISO8583报文(简称8583包)又称8583报文,是一个国际标准的包格式,最多由128个字段域组成,每个域都有统一的规定,并有定长与变长之分. [报文格式] POS终端上送POS中心的消息报文结构 ...