Lightoj 1414 Feb 29

Problem Link:


if 2nd given month is not feb and january ,i will increment the value by 1

and if the first given month is jan or feb and date is less then 29 then i will decrement the value by 1

then for every year i will calculate the difference using a function

let y and yy are two years &&yy>=y &&passing yy and y-1 to function

int leap(int yy,int y,int x)
     return yy/x-y/x;

Then calculations

View Code
using namespace std;
int month(string s)
string months[]={" ","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
vector::iterator it=find(v.begin(),v.end(),s);
return distance(v.begin(), it);
int leap(int y,int yy,int x)
	return y/x-yy/x;

int main() {
		int n,d,dd,y,yy,cs=1;
		char a[24],b[24];
			scanf("%s %d, %d",a,&d,&y);
			scanf("%s %d, %d",b,&dd,&yy);
			int m,mm;
			if(m>2) y++;
			if(mm<2 ||(mm==2 &&dd<29))
			int dif=leap(yy,y,4)-leap(yy,y,100)+leap(yy,y,400);
			cout<<"Case "<<cs++<<": "<<dif<<endl;
	return 0;





About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s