zoukankan      html  css  js  c++  java
  • poj 3393 Lucky and Good Months by Gregorian Calendar 夜

    http://poj.org/problem?id=3393

    伤不起呀 题目也太长了吧

    不过也学到了点常识

    解释见代码注释

    #include<iostream>
    #include<cmath>
    #include<string>
    #include<algorithm>
    #include<queue>
    #include<cstring>
    #include<cstdio>
    
    using namespace std;
    const int K=700000000;
    int Days[15]={0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int Adddays(int ,int);
    int Findwhichday(int year,int month)//求出 某年某月第一天是周几
    {
        int Y=2006,M=7,Theday=6;//以 2006 年 7 月 第一天是 周六 为标准进行计算
        int sum=0;
        if(year<Y||(year==Y&&month<M))//分两种情况,所求时间在参考时间前还是后
        {
            while(year<Y||(Y==year&&month<M))
            {
                sum+=Adddays(year,month);
                ++month;
                if(month==13)
                {++year;month=1;}
            }
            return (Theday+K-sum)%7;
        }
        else
        {
            while(Y<year||(Y==year&&M<month))
            {
                sum+=Adddays(Y,M);
                ++M;
                if(M==13)
                {++Y;M=1;}
            }
            return (sum+Theday)%7;
        }
    }
    int Adddays(int year,int month)//判断某年某月为多少天
    {
        if(year==1752&&month==9)
        return 19;
        if(month!=2)
        return Days[month];
        if(year<1582||year==1700)
        {
            if(year%4==0)
            return Days[month]+1;
            else
            return Days[month];
        }
        else
        {
            if(year%400==0||(year%4==0&&year%100!=0))
            return Days[month]+1;
            else
            return Days[month];
        }
    }
    int main()
    {
        int Startyear,Startmonth;
        int Endyear,Endmonth;
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int Luckmonth=0,Goodmonth=0;
            scanf("%d %d %d %d",&Startyear,&Startmonth,&Endyear,&Endmonth);
            int WhichDay=Findwhichday(Startyear,Startmonth);//开始年月分第一天为周几
            //cout<<WhichDay<<endl;
            while(Startyear<Endyear||(Startyear==Endyear&&Startmonth<=Endmonth))
            {
                if(WhichDay==1||WhichDay==0||WhichDay==6)
                {
                    ++Goodmonth;
                }
                WhichDay+=Adddays(Startyear,Startmonth);
                if((WhichDay-1)%7==5||(WhichDay-1)%7==6||(WhichDay-1)%7==0)
                {
                    ++Luckmonth;
                }
                WhichDay%=7;
                ++Startmonth;
                if(Startmonth==13)
                {
                    Startmonth=1;
                    ++Startyear;
                }
            }
            printf("%d %d\n",Luckmonth,Goodmonth);
        }
        return 0;
    }
    
  • 相关阅读:
    SpringBoot与quartz集成
    SpringBoot 中使用 @Valid 注解 + Exception 全局处理器优雅处理参数验证
    搭建Redis集群和MySQL主从同步
    scanf_s读取键盘输入字符串失败
    含有通配符*的字符匹配(C语言)
    人之患
    TCP socket编程记录(C语言)
    程序变量命名规范(个人)
    h lib dll文件相关部分
    关于inet_ntop、inet_pton中的n和p分别代表的意义
  • 原文地址:https://www.cnblogs.com/liulangye/p/2509515.html
Copyright © 2011-2022 走看看