標籤: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.日期差值