您的位置:首页 > 其它

PATB1028.人口普查(20)

2018-02-12 20:33 411 查看

题目链接:点击打开链接

知识点笔记:

 1.注意比较方法的使用
 2.最后需要判空输出


AC代码:

#include <cstdio>

struct person{
char name[10];
int y,m,d;
}youngest,oldest,left,right,temp;

bool lessEqu(person a,person b){
if(a.y!=b.y) return a.y<=b.y;
else if(a.m!=b.m) return a.m<=b.m;
else  return a.d<=b.d;
}

void init(){
right.y = oldest.y=2014;
left.y = youngest.y = 1814;
right.m=left.m=oldest.m=youngest.m=9;
right.d=left.d=oldest.d=youngest.d=6;
}
int main() {

int n;
int count=0;
scanf("%d",&n);
init();
for(int i=0;i<n;i++){

scanf("%s %d/%d/%d",temp.name,&temp.y,&temp.m,&temp.d);

if(lessEqu(temp,right)&&lessEqu(left,temp)){
count++;
if(lessEqu(temp,oldest))
oldest=temp;
if(lessEqu(youngest,temp))
youngest=temp;

}
}

if(count) printf("%d %s %s\n",count,oldest.name,youngest.name);
else printf("0\n");

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: