pku1207

#include<cstdio>

using namespace std;

int main(){

     int x,y;

    

    while(scanf("%d %d",&x,&y)!=EOF){

     //while(cin>>x>>y){

         int x1=x,y1=y;

       int maxLength=1;//存放最大 cycle length

       if(x1>y1){    //输入可能从大到小,但是输出时又不能改变顺序,所以多声明两个替代变量

               int t=x1;

                x1=y1;

                y1=t;        

       }

       for(int i=x1;i<=y1;++i){

               int temp=i;

               int length=1;//存放每个整数的 cycle length

               while(temp!=1){

                       if(temp%2==1){

                         temp=3*temp+1;

                     }else{

                     temp=temp/2;

                    }

                    ++length;

              }

              maxLength=maxLength>length?maxLength:length;//将大者存放到 maxLength

         }

     

        //cout<<x<<" "<<y<<" "<<maxLength<<endl;

        printf("%d %d %d/n",x,y,maxLength);

     }

     return 0;

}

原文地址:https://www.cnblogs.com/vivizhyy/p/3394896.html