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

Re:怎么老是wrong answer 啊

Posted by liangkangqi at 2006-03-22 22:48:10 on Problem 1207
In Reply To:怎么老是wrong answer 啊 Posted by:clean at 2005-04-26 14:04:31
交换i,j那部分你搞错了:
tem=i;
j=tem;
i=j;
应该改成:
tem=i;
i=j;
j=tem;


> #include<iostream>
> using namespace std;
> int length(int x);
> int main()
> {
> 	long i,j,tem;
> 	int max;
> 	while(cin>>i>>j)
> 	{
> 		cout<<i<<" "<<j<<" ";
> 		if(i>j)
> 		{
> 			tem=i;
> 			j=tem;
> 			i=j;
> 		}
>      	max=0;
> 		for(int m=i;m<=j;m++)
> 		{
>             if(max<length(m))
> 				max=length(m);
> 		}
> 		cout<<max<<endl;	
> 	}
> 	return 0;
> }
> int length(int x)
> {
> 	int count=0;
> 	count=0;
> 	while(x!=1)	
> 	{
> 		count++;
> 		if((x%2)==0)x=x/2;
> 		else
> 			x=(3*x+1) ;
> 	}
> 	return count+1;
> } 

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