当前位置:网站首页>B1028 人口普查
B1028 人口普查
2022-07-27 05:01:00 【叶辰 .】
1028 人口普查 (20 分)
某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。
这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,而今天是 2014 年 9 月 6 日,所以超过 200 岁的生日和未出生的生日都是不合理的,应该被过滤掉。
输入格式:
输入在第一行给出正整数 N,取值在(0,10 的5次方 ];随后 N 行,每行给出 1 个人的姓名(由不超过 5 个英文字母组成的字符串)、以及按 yyyy/mm/dd(即年/月/日)格式给出的生日。题目保证最年长和最年轻的人没有并列。
输出格式:
在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名,其间以空格分隔。
输入样例
5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20
输出样例
3 Tom John
题目分析:
- 创建结构体之后就显得很简单了
代码如下:
#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;
}
边栏推荐
- 集成开发环境Pycharm的安装及模板设置
- JVM上篇:内存与垃圾回收篇七--运行时数据区-堆
- Mysql表的约束
- Could not autowire.No beans of ‘userMapper‘ type found.
- 测试基础5
- Another skill is to earn 30000 yuan a month+
- Knapsack problem DP
- What is the future development direction of software testing engineers?
- 知识点总结(一)
- C language address book management system (linked list, segmented storage of mobile phone numbers, TXT file access, complete source code)
猜你喜欢

Advantages of smart exhibition hall design and applicable industry analysis

Detailed description of polymorphism

Installation and template setting of integrated development environment pychar

微淼联合创始人孙延芳:以合规为第一要义,做财商教育“正规军”

What if Photoshop prompts that the temporary storage disk is full? How to solve the problem that PS temporary storage disk is full?

Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time

Raspberry pie output PWM wave to drive the steering gear

JVM上篇:内存与垃圾回收篇十四--垃圾回收器

34. Analyze flexible.js

What about PS too laggy? A few steps to help you solve the problem
随机推荐
34. Analyze flexible.js
Use of collection framework
2、 MySQL advanced
How to copy Photoshop layers to other documents
Flexible array and common problems
Detailed description of polymorphism
Static and final keyword learning demo exercise
Complete Binary Tree
标准对话框 QMessageBox
35.滚动 scroll
The difference between strlen and sizeof
How do I reset Photoshop preferences? PS method of resetting preferences
TypeScript 详解
Read write separation and master-slave synchronization
Raspberry pie output PWM wave to drive the steering gear
Sub database and sub table
QT menu bar, toolbar and status bar
JVM上篇:内存与垃圾回收篇五--运行时数据区-虚拟机栈
知识点总结(一)
What if Photoshop prompts that the temporary storage disk is full? How to solve the problem that PS temporary storage disk is full?