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

这也WA?想不明白了

Posted by SimoneZ at 2005-03-31 19:50:01 on Problem 1207
#include<iostream.h>

int calculate(int i)
{
	if(i==1) return 1;
	else{
		if(i%2) i=3*i +1;
		else i=i/2;
	}
	return (1+calculate(i));
}

void main()
{
	int inputi,inputj,i;
	while(cin){
		cin>>inputi>>inputj;
		int max=0;
		for(i=((inputi<inputj)?inputi:inputj);i<=((inputi>inputj)?inputi:inputj);i++){//要考虑i 〉j情况
			int temp=calculate(i);
			if(max<temp) max=temp;
		}
		cout<<inputi<<" "<<inputj<<" "<<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