[Login|Register]
New post

Show post

Search forum

Read topic
哪个地方有问题吗? 2010-10-11 02:31:45 zsonglin
#include <iostream>

using namespace std;
int Length(int x)
{
int len=1;
while(x!=1)
{
     if(x%2==0)x=x/2;
     else
         x=(x*3+1);
     len++;
}
return len;
}
int main()
{

int a,b,max;
while(1)
{
    cin>>a>>b;
    max=Length(a);
for(int i=a;i<=b;i++)
{
if(Length(i)>=max)
  max=Length(i);
}
cout<<a<<' '<<b<<' '<<max<<endl;
}

}
Re:哪个地方有问题吗? 2010-10-11 15:24:10 mrhead
1.how do you jump out of the while-loop in main function?
2.The input data in your program which you suppose "a<=b" is not supposed to be according to the question
3.you compute lenght(a) twice.
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.4ms with 1 query(s).