#include <bits/stdc++.h>
using namespace std;
int charge(int);
int main ()
{
int y,y2,m,m2,d,d2,num,a,b;
while(cin>>y>>m>>d>>y2>>m2>>d2)
{
num=0,a=0,b=0;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(y2>y)
{
swap(y2,y),swap(m2,m),swap(d2,d);
}
else if(m2>m&&y2==y) swap(m2,m),swap(d2,d);
else if(d2>d&&y2==y&&m2==m) swap(d2,d);
for(int i=y2;i<=y-1;i++)
{
if(charge(i)) num+=366;
else num+=365;
//cout<<num<<" ";
}
for(int i=0;i<m2-1;i++) a+=month[i];
if(charge(y2)==1&&m2>2) a++;
a+=d2;
b+=d;
for(int i=0;i<m-1;i++) b+=month[i];
if(charge(y)&&m>2) b++;
num+=b-a;
cout<<num<<endl;
}
}
int charge (int a)
{
if (a%4==0 and a%100!=0 or a%400==0)
{
return 1;
}
else
{
return 0;
}
}
#include <bits/stdc++.h>
using namespace std;
int charge(int);
int main ()
{
int y,y2,m,m2,d,d2,num,a,b;
while(cin>>y>>m>>d>>y2>>m2>>d2)
{
num=0,a=0,b=0;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(y2>y)
{
swap(y2,y),swap(m2,m),swap(d2,d);
}
else if(m2>m&&y2==y) swap(m2,m),swap(d2,d);
else if(d2>d&&y2==y&&m2==m) swap(d2,d);
for(int i=y2;i<=y-1;i++)
{
if(charge(i)) num+=366;
else num+=365;
//cout<<num<<" ";
}
for(int i=0;i<m2-1;i++) a+=month[i];
if(charge(y2)==1&&m2>2) a++;
a+=d2;
b+=d;
for(int i=0;i<m-1;i++) b+=month[i];
if(charge(y)&&m>2) b++;
num+=b-a;
cout<<num<<endl;
}
}
int charge (int a)
{
if (a%4==0 and a%100!=0 or a%400==0)
{
return 1;
}
else
{
return 0;
}
}
#include <bits/stdc++.h>
using namespace std;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int e(int d,int g,int f){
int c=d*365;
for(int b=0;b!=d+1;b++)
if(b%4==0&&b%100!=0||b%400==0)
c++;
c+=f;
for(int b=0;b!=(g-1);b++)
c=c+a[b];
if((d%4==0&&d%100!=0||d%400==0)&&((g<2)||(g==2&&f<=29)))
c--;
return c;
}
int main(int argc, char** argv){
cin.tie(0);
ios::sync_with_stdio(false);
int b[2],c[2],d[2];
while(cin>>b[0]>>c[0]>>d[0]>>b[1]>>c[1]>>d[1])
cout<<abs(e(b[0],c[0],d[0])-e(b[1],c[1],d[1]))<<'\n';
}
AC (22ms, 340KB) |
這個終於AC了......