1096.日期差值

來源:互聯網
上載者:User

標籤:span   資料   class   col   日期   while   struct   差值   nbsp   

題目描述:

有兩個日期,求兩個日期之間的天數,如果兩個日期是連續的我們規定他們之間的天數為兩天

輸入:

有多組資料,每組資料有兩行,分別表示兩個日期,形式為YYYYMMDD

輸出:

每組資料輸出一行,即日期差值

範例輸入:

20110412
20110422

範例輸出:

11

 

 

#include<stdio.h>#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0?1:0int dayofmonth[13][2]={    0,0,    31,31,    28,29,    31,31,    30,30,    31,31,    30,30,    31,31,    31,31,    30,30,    31,31,    30,30,    31,31,};struct date{    int day;    int month;    int year;    void nextday()    {        day++;        if(day>dayofmonth[month][ISYEAP(year)]){            day=1;            month++;            if(month>12)            {                month=1;                year++;            }        }    }};int buf[5001][13][32];int Abs(int x){    return x<0?-x:x;}int main(){    date temp;    int cnt=0;    temp.day=1;    temp.month=1;    temp.year=0;    while(temp.year!=5001){        buf[temp.year][temp.month][temp.day]=cnt;        temp.nextday();        cnt++;    }    int d1,m1,y1;    int d2,m2,y2;    while(scanf("%4d%2d%2d",&y1,&m1,&d1)!=EOF)    {        scanf("%4d%2d%2d",&y2,&m2,&d2);        printf("%d\n",Abs(buf[y2][m2][d2]-buf[y1][m1][d1])+1);     }    return 0;}

 

1096.日期差值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.