Uva 13275 - Leap Birthdays solution
Solve in C++:
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int i,p,m,n,count=0,d,y1,y2;
scanf("%lld",&n);
for(i=1; i<=n; i++)
{
count=0;
scanf("%lld%lld%lld%lld",&d,&m,&y1,&y2);
if(m!=2)
printf("Case %lld: %lld\n",i,(y2-y1));
else
{
if(d!=29)
printf("Case %lld: %lld\n",i,(y2-y1));
else
{
for(p=y1; p<=y2; p=p+4)
{
if((p%4==0 && p%100!=0) || p%400==0 )
{
count++;
}
}
printf("Case %lld: %lld\n",i,count-1);
}
}
}
return 0;
No comments