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:哪位能帮我看看为什么错了

Posted by liangzhirong at 2006-08-03 21:39:33 on Problem 1082
In Reply To:哪位能帮我看看为什么错了 Posted by:wanglei at 2004-04-01 13:31:35
> #include <iostream.h>
> #include <string.h>
> const int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
> int nexty,nextm,nextd;
> int leap(int year)
> {
>     if ((year%4==0 && year%100!=0) || year%400==0) return 1;
>     return 0;
> }
> int nextday(int year,int month,int day)
> {
>     nexty=year;
>     nextm=month;
>     nextd=day+1;
>     if (leap(year)){
>        if (month==2 && nextd>29){
> 	   nextd=1;
> 	   nextm++;
>        }
       else                         //add
          if (day>m[month]){        //add
 	   nextd=1;                //add
   	   nextm++;               //add
          }                        //add 

>     }
>     else if (day>m[month]){
> 	   nextd=1;
> 	   nextm++;
>     }

>     if (nextm>12){
>        nextm=1;
>        nexty++;
>     }
>     return 0;
> }
> int exist(int year,int month,int day)
> {
>     if (year>101 || month>12) return 0;
> /*    if (year==101 && (month>11 || day>4)) return 0;  //modify
   =>*/ if (year==101 && (month>11 || month==11 && day>2 )) return 0;

>     if (month==2 && leap(year)){
> 	if (day>29) return 0;
>     }
>     else if (day>m[month]) return 0;
>     return 1;
> }
> int main()
> {
>     char f[105][15][35];
>     int i,j,k,test;
>     int year,month,day;
>     char flag1,flag2;
>     memset(f,'0',sizeof(f));
>     f[101][11][3]='1';
>     for(i=101;i>=0;i--)
>        for(j=12;j>=1;j--)
> 	  for(k=31;k>=1;k--){
> 	      if (!exist(i,j,k)) continue;
> 	      flag1='1';
> 	      flag2='1';
> 	      if (j==12) flag1=f[i+1][1][k];
> 	      else if (exist(i,j+1,k)) flag1=f[i][j+1][k];
> 	      nextday(i,j,k);
> 	      if (exist(nexty,nextm,nextd)) flag2=f[nexty][nextm][nextd];
> 	      if (flag1=='0' || flag2=='0') f[i][j][k]='1';
> 	  }
>     cin>>test;
>     while(test--){
> 	 cin>>year>>month>>day;
> 	 if (f[year-1900][month][day]=='1') cout<<"YES"<<endl;
> 	 else cout<<"NO"<<endl;
>     }
> 
>     return 0;
> }
帮你改好了,final的时候不要犯这些错误^_^

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