当前位置:网站首页>PAT Level B-B1028 Census (20)
PAT Level B-B1028 Census (20)
2022-08-06 22:32:00 【nekoha_dexter】
A town conducts a census and gets the birthdays of all its residents.Now please write a program to find the oldest and youngest people in town.
This ensures that each date entered is legal, but not necessarily reasonable - assuming it is known that there are no people over 200 in town, and today is September 6, 2014, so people over 200Birthdays and unborn birthdays are both unreasonable and should be filtered out.
input format:
The input gives a positive integer N in the first line, the value is (0,105]; the next N lines, each line gives the name of 1 person (a string consisting of no more than 5 English letters), and press
Output format:
Sequentially print the number of valid birthdays, the names of the oldest and youngest on a single line, separated by spaces.
Input sample:
5John 2001/05/12Tom 1814/09/06Ann 2121/01/30James 1814/09/05Steve 11/20/1967Example output:
3 Tom JohnTest point 3: No valid birthday, special judgment output
#include#include#includeusing namespace std;#define year 2014#define month 9#define day 6//Test point 3: no valid birthday, special judgment output//young and old record the youngest and oldest peoplestruct person{string name;int yy,mm,dd;}young = {"", year - 201, month , day}, old ={"", year + 1, month, day};vector table;int main(){int n;cin >> n;for(int i = 0; i < n; ++i){int y,m,d;string name;cin >> name;scanf("%d/%d/%d", &y,&m,&d);//It is possible that the year or month or day of birth exceeds today's dateif(y > year || (y == year && m > month) || (y == year && m == month && d > day)) continue;// It is possible that the year or month or day of birth is over 200 years oldelse if(y < year - 200 || (y == year -200 && m < month) || (y == year - 200 && m == month && d < day)) continue;table.push_back({name, y, m, d});//Year or month or day can be used as a younger judgmentif(y > young.yy || (y == young.yy && m > young.mm) ||(y == young.yy && m == young.mm && d > young.dd))young = {name, y, m, d};//year or month or day can be used as an older judgmentif(y < old.yy || (y == old.yy && m < old.mm) || (y == old.yy && m == old.mm && d < old.dd))old ={name, y, m, d};}//Test point 3, no valid birthday, special sentenceif(table.size() == 0){cout << table.size()< 边栏推荐
猜你喜欢
随机推荐
B. Find The Array
HCIP笔记(十二)
2022-08-05 The sixth group, hidden from spring, study notes
Mel滤波器:模拟人耳对不同频率语音的感知【人类对频率的感知不是线性的】【对低频信号的感知要比高频信号敏感;对1kHz以下,与频率成线性关系;对1kHz以上,与频率成对数关系】【频率越高,感知力越弱】
OpenCV基础图像的基本操作
积极防御体系进阶:《DevSecOps敏捷安全》
第十五天实验-VLAN
【面试】分布式系统幂等性与顺序性及分布式锁
xp系统怎么升级win7系统版本
[WPF] Combobox default style study notes (Presenter and Trigger)
Right in the dictionary order localeCompare compare strings
搞懂源码的三大条件
Convertible bond strategy under R-Breaker
基于TCP的网络聊天系统
Custom Directive Register Custom Directive
从 min 到 max 的随机数
#私藏项目实操分享#精锐5加密锁如何删除锁内许可
Cesium快速上手1-CesiumWidget-Scene结构
逻辑&算术运算
Axure9 basic interactions (2)









