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

Posted by xiaoqiang008 at 2010-04-21 15:54:58 on Problem 1207
#include <stdio.h>
#include <stdlib.h>
int data[10001];
int digui(int n)
{
    int temp;
    if(n==1) return 1;
    if(n<10001&&data[n]!=-1)   return data[n];
    if(n%2==0) temp=n/2;
    else temp=3*n+1;
    if(n>10000) return digui(temp)+1;
    else return data[n]=digui(temp)+1;
}
int main()
{
    int m,n,i,temp,max=0,a;
    for(i=0;i<10001;i++)
        data[i]=-1;
    while(scanf("%d%d",&m,&n)==2&&m>0&&m<10000&&n>0&&n<10000)
    {
        max=0;
        if(m>n) {a=m;m=n;n=a;}
        for(i=m;i<=n;i++)
        {
        temp=digui(i);
        if(temp>max) max=temp;
        }
        printf("%d %d %d\n",m,n,max);
    }

    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