水題 只是卡在細節上 沒有說 輸入一定是 A小于B 呵呵 實現函數 沒有太多的可以說道的地方。。。
# include <stdio.h>
int fun(long a ,int len)


{
if (a ==1)
return len;
else if (a %2 ==0)
return fun(a/2,len+1);
else return fun(3*a+1,len +1);
}
int main()


{
unsigned long a,b;
unsigned long i,max,temp;

while (scanf("%ld%ld",&a,&b)!=EOF)

{
printf("%ld %ld ",a,b);

if(a>b)
{i = a;a=b;b=i;}
for (max = 0,i = a; i <= b; i ++)

{
temp = fun(i,1);
if (max < temp)
max = temp;
}
printf("%ld\n",max);
}
return 0;
}

posted on 2010-04-11 10:41
付翔 閱讀(228)
評論(0) 編輯 收藏 引用 所屬分類:
ACM 數據結構