Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

两个两分钟解决的菜鸟问题。。

Posted by agui0931 at 2009-09-24 22:35:45 on Problem 1207
//第一:如何控制最后一行没有输入?
//第二:我的程序有问题吗?
//谢谢!!!


#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator