| ||||||||||
| 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 | |||||||||
倒底错在哪了???!!!!输出输入完全符合要求啊!//acm 1027
//The 3n + 1 problem
#include <iostream>
using namespace std;
int length=1;
int cycle_length(int n)
{
length=1;
while(n != 1 && n>0 && n<10000)
{
if(n%2)
{
n = 3*n + 1;
length++;
}
else
{
n /= 2;
length++;
}
}
return length;
}
void main()
{
while(cin)
{
int i , j , max;
cin>>i>>j;
cout<<i<<" "<<j<<" ";
if(i>j)
{
int temp=i;
i=j;
j=temp;
}
max = cycle_length(i);
for(int k=i;k<=j;k++)
{
if(cycle_length(k) >= max)
max = cycle_length(k);
}
cout<<max<<endl;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator