Problem link https://www.codechef.com/submit/MEDIC plzzz help!

#include
#include
using namespace std;
main()
{
int t;
cin>>t;
while(t–)
{
string str;
int i,date[3]={0,0,0},j,pills=0;
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
cin>>str;
for(i=0,j=0;str[j]!=’\0’ && i<3;j++)
{
if(str[j]==’:’)
{ i++; }
else
{
date[i]=date[i]*10+str[j]-‘0’;

         }
     }
       if((date[0]%4==0 && date[0]%100) || date[0]%400==0)
        { month[2]++;}

       if(month[date[1]]==30)
       {
           if(date[2]%2==0)
           pills=15+((30-date[2])/2+1);
           else
           pills=16+((30-date[2]-1)/2);
       }
       else if(month[date[1]]==31)
       {
           if(date[2]%2==0)
           pills=(30-date[2])/2+1;
           else
          pills=(31-date[2])/2+1;
       }
       else if(month[date[1]]==28)
       {
           if(date[2]%2==0)
           pills=15+(28-date[2])/2+1;
           else               
           pills=16+(27-date[2])/2+1;
       }
       else if(month[date[1]]==29)
       {
           if(date[2]%2==0)
           pills=(29-date[2]+1)/2;
           else
           pills=(29-date[2])/2+1;
           
       }
       cout<<pills<<endl;
         
     

}

}

bro your code was giving wrong solution for the 2000:04:01.
or we can say for every month having 30 days.
so i changed your code little bit and now it is giving AC.

#include<bits/stdc++.h>
using namespace std;
main()
{
int t;
cin>>t;
while(t–)
{
string str;
int i,date[3]={0,0,0},j,pills=0;
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
cin>>str;
for(i=0,j=0;str[j]!=’\0’ && i<3;j++)
{
if(str[j]==’:’)
{ i++; }
else
{
date[i]=date[i]*10+str[j]-‘0’;

     }
 }
   if((date[0]%4==0 && date[0]%100) || date[0]%400==0)
    { month[2]++;}

   if(month[date[1]]==30)
   {
       /*
       if(date[2]%2==0)
       pills=15+((30-date[2])/2+1);
       else
       pills=16+((30-date[2]-1)/2);
      */
       pills=((30-date[2]+31)/2)+1;
   }
   else if(month[date[1]]==31)
   {
       if(date[2]%2==0)
       pills=(30-date[2])/2+1;
       else
      pills=(31-date[2])/2+1;
   }
   else if(month[date[1]]==28)
   {
       if(date[2]%2==0)
       pills=15+(28-date[2])/2+1;
       else               
       pills=16+(27-date[2])/2+1;
   }
   else if(month[date[1]]==29)
   {
       if(date[2]%2==0)
       pills=(29-date[2]+1)/2;
       else
       pills=(29-date[2])/2+1;
       
   }
   cout<<pills<<endl;

}
}

thanks a lot brother

1 Like

welcome bro