zoukankan      html  css  js  c++  java
  • 日期

    #include<bits/stdc++.h>
    using namespace std;
    int tans(char *s){
        if(!strcmp(s,"January")){
            return 1;
        }else if(!strcmp(s,"February")){
            return 2;
        }else if(!strcmp(s,"March")){
            return 3;
        }else if(!strcmp(s,"April")){
            return 4;
        }else if(!strcmp(s,"May")){
            return 5;
        }else if(!strcmp(s,"June")){
            return 6;
        }else if(!strcmp(s,"July")){
            return 7;
        }else if(!strcmp(s,"August")){
            return 8;
        }else if(!strcmp(s,"September")){
            return 9;
        }else if(!strcmp(s,"October")){
            return 10;
        }else if(!strcmp(s,"November")){
            return 11;
        }else if(!strcmp(s,"December")){
            return 12;
        }
    }
    bool isleap(int year){
        if(year%400==0)
            return 1;
        if(year%4==0&&year%100!=0)
            return 1;
        return 0;
    }
    int main(){
        int t,cnt=0;
        char mm1[20],mm2[20];
        int day1,day2,year1,year2,month1,month2;
        scanf("%d",&t);
        while(t--){
            scanf("%s %d, %d",mm1,&day1,&year1);
            scanf("%s %d, %d",mm2,&day2,&year2);
            month1=tans(mm1);
            month2=tans(mm2);
            if(year2<year1){
                swap(year1,year2);
                swap(month1,month2);
                swap(day1,day2);
            }else if(year1==year2&&month1>month2){
                swap(month1,month2);
                swap(day1,day2);
            }else if(year1==year2&&month1==month2&&day1>day2){
                swap(day1,day2);
            }
    //        printf("1]  %d %d %d
    ",year1,month1,day1);
    //        printf("2]  %d %d %d
    ",year2,month2,day2);
            int num2,num1,num;
            num2=year2/400+year2/4-year2/100;
            num1=(year1-1)/400+(year1-1)/4-(year1-1)/100;
            num=num2-num1;
            if(isleap(year2)){
                if(month2==1||month2==2&&day2<29){
                    num--;
           //         printf("%d+++++
    ",num);
                }
            }
            if(isleap(year1)){
                if(month1>=3){
                    num--;
             //       printf("%d-----
    ",num);
                }
            }
    
            printf("Case %d: %d
    ",++cnt,num);
        }
    
        return 0;
    }
    /*
    5
    August 12, 2000
    August 12, 2005
    
    */
    

      

  • 相关阅读:
    iOS开源App整理
    iOS9 3DTouch 之 Home Screen Quick Actions
    UITabbarController & UITabbar 学习
    Linux一些最基础操作
    logo的表现形式
    LOGO设计中出现文字背后的意义
    标志设计中选择合适的字体
    sketch制作LOGO(三) ---大熊猫
    sketch制作LOGO(二) ---樱花婆婆
    十多个app引导页面欣赏
  • 原文地址:https://www.cnblogs.com/chengsheng/p/4679973.html
Copyright © 2011-2022 走看看