HDOJ HDU 1032 The 3n + 1 problem ACM 1032 IN HDU

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

题目地址:
          http://acm.hdu.edu.cn/showproblem.php?pid=1032

水题,不解释..........................

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

#include
< stdio.h >
int  Length( int  n)
{
     
int  k = 0 ;
     
while (n != 1 )
     {
           
if (n % 2 == 1 )
                 n
= 3 * n + 1 ;
           
else
                 n
/= 2 ;
           k
++ ;
     }
     
return  (k + 1 );
}
int  main( )
{
     
int  i,j,temp,max,t,small,large; 
     
while (scanf( " %d " , & i) != EOF) 
     {
           scanf(
" %d " , & j);
           
if (i <= j)
           {
            small
= i;large = j;
           }
           
else  { 
                 small
= j;large = i;
                 }   
           temp
= small;
           max
= Length(temp);
           
while (temp <= large)
           {
                 t
= Length(temp);
                 
if (t > max)
                       max
= t;
                 temp
++ ;
           }
           printf(
" %d %d %d\n " ,i,j,max);
     }
     
return   0 ;
}

你可能感兴趣的:(HDOJ HDU 1032 The 3n + 1 problem ACM 1032 IN HDU)