PTA乙级 (*1028 人口普查 (20分))

时间:2020-02-01 01:00:05   收藏:0   阅读:90

1028 人口普查 (20分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805293282607104

#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	char chr[6],maxchr[6],minchr[6];
	int year,month,day,length,count=0;
	int maxlength=20140907,minlength=18140905;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%s %d/%d/%d",chr,&year,&month,&day);
		length=year*10000+month*100+day;
		if(length>=18140906&&length<=20140906){
			count++;
			if(length<maxlength)
			{
				strcpy(maxchr,chr);
				maxlength=length;
			}
			if(length>minlength)
			{
				strcpy(minchr,chr);
				minlength=length;
			}
		}
	}
	if(count) cout<<count<<" "<<maxchr<<" "<<minchr<<endl;
	else cout<<"0"<<endl;
	return 0;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!