12439 - February 29

All about problems in Volume 124. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
mamun30cse
New poster
Posts: 4
Joined: Mon May 05, 2014 7:26 am

12439 - February 29

Post by mamun30cse » Mon Jun 06, 2016 8:12 am

Time limit!!!! help0 Please.

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
const string month[]={"January","February","March","April","May","June","July",
"August","September","October","November","December"};

int main()
{
int TestCases,serial=1;
cin>>TestCases;
while(TestCases--)
{
//declaring variables
int date1,year1,date2,year2,Leap_year=0;
string month1,month2,comma;
//taking input
cin>>month1>>date1>>comma>>year1;
//calculating month1 position
int month_position=distance(month,find(month,month+12,month1));
//determining initial year
if(month_position>1) year1++;
cin>>month2>>date2>>comma>>year2;
//calculating month2 position
month_position=distance(month,find(month,month+12,month2));
if(month_position<1) year2--;
else if(month_position==1 && date2<29) year2--;
//calculating leap year
for(int i=year1;i<=year2;i++)
{
if(i%4==0)
{
if(i%100!=0) Leap_year++;
else if(i%100==0 && i%400==0) Leap_year++;
}
}
cout<<"Case "<<serial++<<": "<<Leap_year<<endl;
}
return 0;
}

Post Reply

Return to “Volume 124 (12400-12499)”

Who is online

Users browsing this forum: No registered users and 1 guest