#3583: 我的天阿~~~~~~ SOS


return3244 (3244)


 
請好心的大大幫小弟看看錯在哪(感恩啦~~) 
另外可否給點建議,說如何簡化(實在太長了><!)
int year,month,day,a;
int ERROR_YEAR()
{
  if (year==0 && month==2)
  {
    if (day==29)
      return (0);
    else
      return (1); 
  } 
}
int WHITCH_MONTH()
{
  switch(a)
  {
    case 1:case 3:case 5: case 7:case 8:case 10:case 12:
      return (31);
      break;
    case 2:
      if (year==0)
        return (28);
      if (year%4==0 && year%100!=0 || year%400==0)
        return (29);
      else 
        return (28);
      break;
    default :
      return (30);
  }    
}
int ERROR_MONTH()
{
  if (month<13 && month>0)
    return(1);
  else
    return(0);  
}

int ERROR_DAY()
{
  switch(month)
  {
    case 2:
      if (WHITCH_MONTH())
        if (day<30 && day>0)
          return(1);
        else
          return(0);
      break;
    case 1:case 3:case 5:case 7:case 9:case 11:
      if (day<31 && day>0)
        return(1);
      else 
        return(0);
        break;
    default :
      if (day<32 && day>0)
        return(1);
      else 
        return(0);
        break;
  }   
}

int main()
  int sum=0;
  while(cin  >>year>>month>>day)
  {
    if (ERROR_YEAR())
    { 
      if (year<0)
      {
        cout <<"Error"<<endl;
        break; 
      }
      if (ERROR_MONTH())
      { 
        if (ERROR_DAY())
        {
          for (a=1; a<=month; a++)
          {
            if (a==month)                         
              sum=day+sum;          
            else
              sum=sum+WHITCH_MONTH();
          }
        if (sum==1)
          cout <<"It is "<<sum<<" day in "<<year<<endl;
        else
          cout <<"It is "<<sum<<" days in "<<year<<endl;
        }
        else
          cout <<"Error"<<endl;
        }
      }
      else
        cout <<"Error"<<endl;
      sum=0;
    
  }
  return 0;
}

#3589: Re:我的天阿~~~~~~ SOS


linishan (L)


請好心的大大幫小弟看看錯在哪(感恩啦~~) 
另外可否給點建議,說如何簡化(實在太長了>
int year,month,day,a;
int ERROR_YEAR()
{
  if (year==0 && month==2)
  {
    if (day==29)
      return (0);
    else
      return (1); 
  } 
}
int WHITCH_MONTH()
{
  switch(a)
  {
    case 1:case 3:case 5: case 7:case 8:case 10:case 12:
      return (31);
      break;
    case 2:
      if (year==0)
        return (28);
      if (year%4==0 && year%100!=0 || year%400==0)
        return (29);
      else 
        return (28);
      break;
    default :
      return (30);
  }    
}
int ERROR_MONTH()
{
  if (month<13 && month>0)
    return(1);
  else
    return(0);  
}

int ERROR_DAY()
{
  switch(month)
  {
    case 2:
      if (WHITCH_MONTH())
        if (day<30 && day>0)
          return(1);
        else
          return(0);
      break;
    case 1:case 3:case 5:case 7:case 9:case 11:
      if (day<31 && day>0)
        return(1);
      else 
        return(0);
        break;
    default :
      if (day<32 && day>0)
        return(1);
      else 
        return(0);
        break;
  }   
}

int main()
  int sum=0;
  while(cin  >>year>>month>>day)
  {
    if (ERROR_YEAR())
    { 
      if (year<0)
      {
        cout <<"Error"<
        break; 
      }
      if (ERROR_MONTH())
      { 
        if (ERROR_DAY())
        {
          for (a=1; a<=month; a++)
          {
            if (a==month)                         
              sum=day+sum;          
            else
              sum=sum+WHITCH_MONTH();
          }
        if (sum==1)
          cout <<"It is "<
        }
      }
      else
        cout <<"Error"<
      sum=0;
    
  }
  return 0;
}


我的建議是
你可以宣告一個陣列放置 每一月的天數
只需要把2當作special case
ex. int m[]={31,28,31,30,31....}