标签: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:0 int 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; }
标签:span 数据 class col 日期 while struct 差值 nbsp
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736457.html