< Back to forum

### codechef question code "MEDIC" getting WA. Couldn't find the error.

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {

``````ios_base::sync_with_stdio(false) ;
cin.tie(NULL) ;

ll t ;
cin >> t ;
while (t--)
{
ll d=0, m=0, y=0, ans=0 ;
string date ;
string mon="", dat="", year="" ;
getline (cin >> ws, date) ;
mon=mon+date[5]+date[6] ;
m=stoi(mon) ;
dat=dat+date[8]+date[9] ;
d=stoi(dat) ;
year=year+date[0]+date[1]+date[2]+date[3] ;
y=stoi(year) ;
if(m%2==0 && m!=2)
{
if(d%2==0)
ans=((30-d)/2)+16 ;
else
ans=((31-d)/2)+16 ;
}
else if (m==2)
{
if (y%4==0 && y!=1900)
{
if(d%2==0)
ans=(30-d)/2 ;
else
ans=((29-d)/2)+1 ;
}
else
{
if(d%2==0)
ans=(28-d)/2+16 ;
else
ans=((29-d)/2)+16 ;
}
}
else
{
if(d%2==0)
ans=(32-d)/2 ;
else
ans=((31-d)/2)+1 ;
}
cout << ans << endl ;
}
return 0 ;
``````

}

Asked by: Anonymous on March 29, 2020, 2:03 p.m. Last updated on March 29, 2020, 2:03 p.m.

if y is divisible by 400 , then it is a leap year or if y is div by 4 and not divisible by 100, then it is a leap year

also both july and august have 31 days

Preview

##### Enter your comment details below:

Preview

You have considered Aug,Oct,Dec as 30 days month. But actually they are of 31 days.

So if you change (m%2==0 && m!=2) to (m==4 || m==6 || m=9 || m==11) it should work.

anujpatel181299 last updated on March 31, 2020, 1:23 a.m.

##### Instruction to write good question
1. 1. Write a title that summarizes the specific problem
2. 2. Pretend you're talking to a busy colleague
3. 3. Spelling, grammar and punctuation are important!