当前位置:网站首页>B1028 census
B1028 census
2022-07-27 05:20:00 【Ye Chen】
1028 The census (20 branch )
A census was conducted in a town , Got all the residents' birthdays . Now please write a program , Find out the oldest and youngest people in town .
Make sure that every date you enter is legal , But it's not necessarily reasonable —— Suppose there's no more than 200 Old man , And today is 2014 year 9 month 6 Japan , So over 200 Birthday and unborn birthday are unreasonable , It should be filtered out .
Input format :
The input gives a positive integer on the first line N, The value is (0,10 Of 5 Power ]; And then N That's ok , Each line gives 1 Personal name ( By no more than 5 A string of English letters )、 And press yyyy/mm/dd( That is the year / month / Japan ) Birthday given in format . The title ensures that the oldest and youngest people are not tied .
Output format :
Output the number of valid birthdays in order in one line 、 The names of the oldest and youngest people , Separated by spaces .
sample input
5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20
sample output
3 Tom John
Topic analysis :
- After creating the structure, it is very simple
The code is as follows :
#include<bits/stdc++.h>
using namespace std;
struct people{
string name;
int old;
}p[100100];
int main(){
int n,count=0;
string s;
cin>>n;
for(int i=0;i<n;i++){
cin>>p[i].name>>s;
p[i].old=(s[0]-'0')*10000000+(s[1]-'0')*1000000+(s[2]-'0')*100000+(s[3]-'0')*10000+(s[5]-'0')*1000+(s[6]-'0')*100+(s[8]-'0')*10+(s[9]-'0');
if(p[i].old<=20140906&&20140906-p[i].old<=2000000){
count++;
}
}
if(count==0){
cout<<"0"<<endl;
return 0;
}
int max=0,min=100000000;
for(int i=0;i<n;i++){
if(p[i].old<=20140906&&20140906-p[i].old<=2000000){
if(p[i].old<min){
min=p[i].old;
}
if(p[i].old>max){
max=p[i].old;
}
}
}
for(int i=0;i<n;i++){
if(min==p[i].old){
min=i;
}
if(max==p[i].old){
max=i;
}
}
cout<<count<<" "<<p[min].name<<" "<<p[max].name<<endl;
}
边栏推荐
- LocalDateTime和ZonedDateTime
- Could not autowire. No beans of ‘userMapper‘ type found.
- [untitled] I is circularly accumulated under certain conditions. The condition is usually the length of the loop array. When it exceeds the length, the loop will stop. Because the object cannot judge
- JVM上篇:内存与垃圾回收篇五--运行时数据区-虚拟机栈
- Invert a Binary Tree
- Installation and template setting of integrated development environment pychar
- Tcp server是如何一个端口处理多个客户端连接的(一对一还是一对多)
- Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
- During its low-level period, this slave edge causes the instruction number to make a corresponding model
- 传智教育|软件测试工程师未来的发展方向有哪些?
猜你喜欢

1、 MySQL Foundation

整合SSM

Installation and template setting of integrated development environment pychar

How idea creates a groovy project (explain in detail with pictures and texts)

JVM上篇:内存与垃圾回收篇--运行时数据区四-程序计数器

素数筛选(埃氏筛法,区间筛法,欧拉筛法)

JVM Part 1: memory and garbage collection -- runtime data area 4 - program counter

B1021 个位数统计

简化JDBC的MyBits框架

Constraints of MySQL table
随机推荐
JVM Part 1: memory and garbage collection part 9 - runtime data area - object instantiation, memory layout and access location
Invert a Binary Tree
DBUtils
探寻通用奥特能平台安全、智能、性能的奥秘!
Advantages of smart exhibition hall design and applicable industry analysis
文件处理(IO)
Introduction to Kali system ARP (network disconnection sniffing password packet capturing)
Card drawing program simulation
数据库设计——关系数据理论(超详细)
LocalDateTime和ZonedDateTime
Standard dialog qmessagebox
JVM上篇:内存与垃圾回收篇八--运行时数据区-方法区
Installation and template setting of integrated development environment pychar
集合框架的使用
JVM Part 1: memory and garbage collection -- runtime data area 4 - program counter
How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
Scientific Computing Library -- Matplotlib
Event
Flexible array and common problems