Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:实在是 不容易啊 ~ 终于 AC~

Posted by huanghaoxiang at 2009-10-05 23:04:20 on Problem 2080
In Reply To:实在是 不容易啊 ~ 终于 AC~ Posted by:810974380 at 2009-08-20 16:07:02
> 一直搞错了个问题,用if else   判断平年 闰年
> 由于偷懒  直接把闰年的一段 复制到平年上面,
> 有个地方没注意修改,结果出现问题了,我不管是
> 平年还是闰年都减去了闰年月份上面的天数,导致有些天数是
> 0,比如1429输出11月29 而1430输出12月0  我一直发现不了错误~~~
> 
> 总算改过来了~
> 
> 希望大家不要和我一样偷懒,代码还是要一个一个打,复制粘贴
> 时有些细节会漏掉的~
> 
> 切记切记!~~~
> 
> 
> 
> 
> 附上代码,以供参考~
> 
> #include<stdio.h>
> #include<stdlib.h>
> char *str[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
> int a[12]={31,59,90,120,151,181,212,243,273,304,334,365};
> int b[12]={31,60,91,121,152,182,213,244,274,305,335,366};
> int search1(int n)  //查找平年的月份
> {int i=0;
>  while(1)
>  { if(n<=a[i]) break;
>    i++;
>  }
>  return i;
> }
> int search2(int n)   //查找闰年的月份
> {int j=0;
>  while(1)
>  {  if(n<=b[j]) break;
>     j++;
>  }
>  return j;
> }
> int main()
> {  
>    int n,w,x,y,t,day,month;              
>    while(scanf("%d",&n)){
>    if(n==-1) break;
>    w=n;
>    n++;
>    x=2000;
>    
>    while(n>366)
>    {if((x%4==0&&x%100!=0)||x%400==0)
>     n-=366;
>     else n-=365;
>     x++;
>    }
>    
>   if(n==366&&!((x%4==0&&x%100!=0)||x%400==0))
>    {n-=365;x++;}
>    
>   if((x%4==0&&x%100!=0)||x%400==0)
>    y=1;
>    else y=0;
>    
>   switch((y==1)?(1):(0))
>    {
>    case 1:
>    {t=search2(n);
>     if(t==0)day=n;
>     else day=n-b[t-1];
>     month=t+1;
>     
>    printf("%d-%02d-%02d %s\n",x,month,day,str[(w+6)%7]);
>     break;}
>    
>   case 0:
>  {   t=search1(n);
>     if(t==0) day=n;
>     else day=n-a[t-1];
>     month=t+1;
>     
>    printf("%d-%02d-%02d %s\n",x,month,day,str[(w+6)%7]);
>    break;}    
>   }    
>   }
>   
>   system("pause");
>   return 0;
> } 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator