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 afc163 at 2006-03-26 15:01:01 on Problem 1207
//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:
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