• Confusing Date Format UVALive 7711 给定mm-mm-mm格式的时间。年份(1900-1999)只给了后两位数,问有多少种合法的排列使时间正确。


    /**
    题目:Confusing Date Format UVALive 7711
    链接:https://vjudge.net/contest/174844#problem/A
    题意:给定mm-mm-mm格式的时间。年份(1900-1999)只给了后两位数,问有多少种合法的排列使时间正确。
    思路:
    
    第一次:快速读题,题意不清,没注意到这句话,
    
    To punish teams who did not read this problem statement carefully, we’ll add one trick input: if the
    input is “
    04-05-01
    ”, the output should be 1 (not 6).
    
    第二次:闰年判断写错了,
    
    错的:if(y%4==0&&(y%100!=0||y%400==0)) 对的:if((y%4==0&&y%100!=0)||y%400==0) 。
    
    第三次:没有判重,假设输入的数字是04-04-04,那么交换位置后,year,month,day会多次出现1904-04-04.
    
    */
    
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<map>
    #include<vector>
    #include<queue>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef pair<int,int> P;
    typedef long long LL;
    const int N = 3e5+10;
    const int mod = 1e9+7;
    const int INF = 0x3f3f3f3f;
    int f[100][100][100];
    bool ryear(int y)
    {
        if((y%4==0&&y%100!=0)||y%400==0){
            return true;
        }
        return false;
    }
    int judge(int year,int month,int day)
    {
        if(f[year][month][day]) return 0;
        f[year][month][day] = 1;
        year += 1900;
        if(year>=2000||year<1900) return 0;
        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
            if(day>=1&&day<=31) return 1;
            else return 0;
        }
        if(month==4||month==6||month==9||month==11){
            if(day>=1&&day<=30) return 1;
            else return 0;
        }
        if(month==2){
            if(ryear(year)){
                if(day>=1&&day<=29) return 1;
                return 0;
            }else
            {
                if(day>=1&&day<=28) return 1;
                return 0;
            }
        }
        return 0;
    }
    int main(void)
    {
        int T;
        int cas = 1;
        cin>>T;
        int x, y, z;
        while(T--)
        {
            scanf("%d-%d-%d",&x,&y,&z);
            if(x==4&&y==5&&z==1){
                printf("Case #%d: %d
    ",cas++,1); continue;
            }
            memset(f, 0, sizeof f);
            int ans = 0;
            ans += judge(x,y,z);
            ans += judge(x,z,y);
            ans += judge(y,x,z);
            ans += judge(y,z,x);
            ans += judge(z,x,y);
            ans += judge(z,y,x);
            printf("Case #%d: %d
    ",cas++,ans);
        }
        return 0;
    }
  • 相关阅读:
    关于celery django djangocelery搭配报错问题及解决方法
    django 1048错误原因及解决思路
    CSS ::Selection
    Win7编程:在按钮中加入管理员权限运行盾牌图标转载
    VisualStudioVS2010统计代码行数
    在套用母版页的页面中应用input file上传图片
    Asp.Net Url 传值出现乱码的解决方法(包括js传值)
    JS验证码刷新无反应原因
    AspnetPager
    fckeditor2.6在IE9下的弹出窗口报错问题解决
  • 原文地址:https://www.cnblogs.com/xiaochaoqun/p/7267107.html
Copyright © 2020-2023  润新知