hdu 2005

来源:互联网 发布:买一个域名要多少钱 编辑:程序博客网 时间:2024/05/01 12:43
 

#include<stdio.h>
  int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  int isLeapyear(int n)
  {
   if(n%4==0&&n%100!=0||n%400==0) return 1;
   return 0;
  }
  int main()
  {
   int i,k,Y,M,D;
   char ch[20];
   while(scanf("%d/%d/%d",&Y,&M,&D)!=EOF) //特殊读法
   {
   k=D;
   for(i=1;i   i=isLeapyear(Y);
   if(M>2&&i)k++;
   printf("%d\n",k);
   }
   return 0;
  }
  
  一下是自己写的代码,提交Wrong Answer:
  #include<stdio.h>
  int main()
  {
   int year,month,day,count,i,m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
   while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
   {
   count=0;
   for(i=1;i   count+=m[i];
   count+=day;
   if((year%4==0&&year%100!=0)||(year%400==0))
   count+=1;
   printf("%d\n",count);
   }
  }
 

 

 
/*#include <iostream>
using namespace std;
int main()
{
  int year,month,day,total=0;
  int x[2][13]={

      {0,31,28,31,30,31,30,31,31,30,31,30,31},
      {0,31,29,31,30,31,30,31,31,30,31,30,31}

};
  while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
  {
      total=0;
      for(int i=1;i<month;i++)
       {
        if((year%4==0) || (year%100!=0 && year%400==0))//能被4整除不能被100整除或者能被400整除是闰年(这里程序有误)
              total+=x[1][i];
        else //if(year%4!=0 && (year%100==0 || year%400!=0))
              total+=x[0][i];
        }
        total+=day;
        cout<<total<<endl;
  }
  system ("pause");
  return 0;
}

 

为甚麽本地通过,hdu上却说wrong answer?

因为闰年判断条件错误!!!!!!!!1

#include <iostream>
using namespace std;

int main()
{
  int year,month,day,total;
  int x[2][13]={
      {0,31,28,31,30,31,30,31,31,30,31,30,31},
      {0,31,29,31,30,31,30,31,31,30,31,30,31}
      };
  while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
  {
      total=0;
      for(int i=1;i<month;i++)
       {
        if(year%4==0 && (year%100!=0 || year%400==0))//能被4整除不能被100整除或者能被400整除的是闰年!,a其实闰年每四年一次!!!!!!!!!!!!
              total+=x[1][i];
        else
            total+=x[0][i];
        }
        total+=day;
        cout<<total<<endl;
  }
  system ("pause");
  return 0;
}
*/

 

 

 

 

 

 

 

 


/*以上程序输入年月日,输出这一年的第几天,
 数组~解决了月份不同的问题
 total=0~解决了 (这类while(cin>>n)置0的问题)
 1985/1/20
2006/3/12
输出为
20
91
的问题
正确答案为
20
71
 
 


 /* 改进之前的程序*/
/*

 while(scanf("%d/%d/%d",&year,&month,&day))
  {
    if((year%4==0) || (year%100!=0 && year%400==0))
      for(int i=0;i<month-1;i++)
        total+=x[1][i];
    else
      for(int i=0;i<month-1;i++)
        total+=x[0][i];
        total+=day;
        cout<<total<<endl;
  }
  system ("pause");
  return 0;
}

*/


 

原创粉丝点击