计算两个日期之差
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int month1[13]={0, 31, 28, 31, 30, 31, 30, 31,31,30,31,30,31};
int month2[13]={0, 31, 29, 31, 30, 31, 30, 31,31,30,31,30,31};
int date(char *str)
{
int y, m, d;
y = m = d = 0;
for(int i=0; i<4; i++)
y += int(pow(10,3-i))*(str[i] - '0');
m += 10*(str[4] - '0');
m += (str[5] - '0');
d += 10*(str[6] - '0');
d += (str[7] - '0');
int sum = 0;
for(int i= 1; i<y; i++)
if(i%400 == 0 || (i%100 != 0 && i%4 == 0) )
sum += 366;
else
sum += 365;
if(y%400 == 0 || (y%100 != 0 && y%4 == 0) )
{
for(int i=1; i<m; i++)
sum += month2[i];
}
else
{
for(int i=1; i<m; i++)
sum += month1[i];
}
sum += d;
return sum;
}
int main()
{
char str[10];
int sum1, sum2;
while(gets(str))
{
sum1 = date(str);
gets(str);
sum2 = date(str);
printf("%d\n",abs(sum2 - sum1)+1);
}
system("pause");
return 0;
}