| ||||||||||
| 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 | |||||||||
两个两分钟解决的菜鸟问题。。//第一:如何控制最后一行没有输入?
//第二:我的程序有问题吗?
//谢谢!!!
#include<iostream>
using namespace std;
int main()
{
int n,begin,end,h,max,temp,flag;
while(cin>>begin)
{
cin>>end;
flag=0;
if(begin>end)
{
temp=end;
end=begin;
begin=temp;
flag=1;
}
max=0;
for(n=begin;n<=end;n++)
{
h=1;
temp=n;
while(temp!=1)
{
if(temp%2==1)
temp=3*temp+1;
else
temp=temp/2;
h++;
if(max<h)
max=h;
//cout<<temp<<endl;
//if(h=16)
//break;
}
}
if(flag==1)
{
temp=end;
end=begin;
begin=temp;
}
cout<<begin<<" "<<end<<" "<<max<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator