PAT (Basic Level) Practice (中文)- 1028 人口普查(20 分)

简介: PAT (Basic Level) Practice (中文)- 1028 人口普查(20 分)

题目链接:点击打开链接

题目大意:略。

解题思路:


题目很单纯认为一年(一岁)就是yyyy相差1即可。无需考虑闰年/平年。

日期比较 y*10000 + m*100 + d 小技巧。

注意:合理数为 0 的情况,由于名字输出空,所以报的是 PE,而不是 WA。

AC 代码

#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
    const int MAX=20140906,MIN=18140906;
    int n,mi=INF,ma=-1,y,m,d,rs,cnt=0; scanf("%d",&n);
    string s1,s2;
    char s[10];
    for(int i=0;i<n;i++)
    {
        scanf("%s%d/%d/%d",s,&y,&m,&d);
        rs=y*10000+m*100+d;
        if(!(rs>MAX || rs<MIN))
        {
            cnt++;
            if(rs>ma) ma=rs,s1=s;
            if(rs<mi) mi=rs,s2=s;
        }
    }
    if(cnt==0) puts("0");
    else printf("%d %s %s\n",cnt,s2.c_str(),s1.c_str());
    return 0;
}
目录
相关文章
|
11月前
|
C语言 C++
PAT (Basic Level) Practice (中文)1099 性感素数(20分)
“性感素数”是指形如 (p, p+6) 这样的一对素数。之所以叫这个名字,是因为拉丁语管“六”叫“sex”(即英语的“性感”)。(原文摘自 http://mathworld.wolfram.com/SexyPrimes.html) 现给定一个整数,请你判断其是否为一个性感素数。
90 0
|
算法
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
76 0
PAT (Basic Level) Practice (中文) 1036 跟奥巴马一起编程 (15 分) p89
PAT (Basic Level) Practice (中文) 1036 跟奥巴马一起编程 (15 分) p89
126 0
|
存储 测试技术
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
63 0
PAT (Basic Level) Practice (中文) 1016 部分A+B (15 分)
PAT (Basic Level) Practice (中文) 1016 部分A+B (15 分)
64 0
|
C语言
PAT (Basic Level) Practice (中文) B1026 程序运行时间 (15 分)
PAT (Basic Level) Practice (中文) B1026 程序运行时间 (15 分)
96 0
PAT (Basic Level) Practice (中文) B1046 划拳 (15 分)
PAT (Basic Level) Practice (中文) B1046 划拳 (15 分)
59 0
|
测试技术
PAT (Basic Level) Practice (中文) B1011 A+B 和 C (15 分)
PAT (Basic Level) Practice (中文) B1011 A+B 和 C (15 分)
76 0
PAT (Basic Level) Practice (中文) B1011 A+B 和 C (15 分)
|
存储
PAT (Basic Level) Practice (中文) 1041 考试座位号 (15 分)
PAT (Basic Level) Practice (中文) 1041 考试座位号 (15 分)
64 0
PAT (Basic Level) Practice (中文) 1041 考试座位号 (15 分)
PAT (Basic Level) Practice (中文)- 1073 多选题常见计分法(20 分)
PAT (Basic Level) Practice (中文)- 1073 多选题常见计分法(20 分)
103 0