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

我现在用数组存数,代码如下,自己测试没有错误,提交怎么会是Wrong Answer,请大家运行指点一下 8-)

Posted by bjtu01281229 at 2005-05-23 03:17:20
In Reply To:2084 请教一个简单题:关于母函数的,为什么会出错,觉得没错呀? Posted by:bjtu01281229 at 2005-05-20 03:25:48
#include <iostream>
#include <math.h>
using namespace std;
int  main()
{
    int h1[50]={0},h2[50]={0},h3[50]={0},hn[50]={0};
    int num1=1,k,over=0;
    h1[0]=2;h2[0]=1;
    cin>>k;
    while(k!=-1)
     {
       if(k==1||k==2)cout<<k;
       else{
            for(int n=3;n<=k;n++)
                 {           for(int i=1;i<=num1;i++){h3[i-1]=h1[i-1];}
                             for(int j=1;j<=num1;j++)
                             {
                              h1[j-1]=h1[j-1]*3; h1[j-1]=h1[j-1]+over;over=h1[j-1]/10;h1[j-1]=h1[j-1]%10;
                             }
                      if(over>0){num1++;h1[num1-1]=over;}
                      over=0;
                      for(int y=1;y<=num1;y++)
                           {
                            hn[y-1]=h1[y-1]-h2[y-1]-over;
                            if(hn[y-1]<0){hn[y-1]=hn[y-1]+10;over=1;}
                            else over=0;
                           }
                       over=0;
                       if(hn[num1-1]==0){num1--;h1[num1-1]=0;}
                       for(int r=1;r<=num1;r++)
                         { h2[r-1]=h3[r-1];h1[r-1]=hn[r-1];
                          }   
                                           
                   }
                   for(int t=num1;t>=1;t--)cout<<hn[t-1];
               }     
      cout<<endl;
      cin>>k;
      num1=1;
      for(int n=0;n<=49;n++){h1[n]=0;h2[n]=0;hn[n]=0;h3[n]=0;}
      h1[0]=2;h2[0]=1;
      }
 
    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