Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮看看这段代码有什么问题,怎么总是wrong answer#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator