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

你自己想想while的判断顺序就明白了

Posted by hawk at 2004-03-02 22:29:12 on Problem 1207
In Reply To:过了,但是不知道为什么。为什么把cin>>a>>b;拿到外面来下面再写一次就行?如下 Posted by:faononl at 2004-03-02 22:24:39
> #include <iostream.h>
> void main()
> {
> 	int a, b ,i ,num , max ,temp ;
> cin >> a >> b ;
> 	while(cin)
> {
> 
> 	
> 	max = 0 ;
> 	cout << a << ' ' << b ;
> 	if ( a >b ) {temp = a ;a = b ;b = temp ;}
> 	for( i = a ; i<=b ; i++ )
> 	{
> 		temp = i ;
> 		num = 1 ;
> 		while(temp != 1 )
> 		{
> 			if ( temp % 2 == 0 ) temp/=2 ;
> 			else temp=temp*3+1 ;
> 			num++ ;
> 		}
> 		if ( num > max ) max = num ;
> 	}
> 	cout << ' ' << max << endl;
> 	cin >> a >> b ;
> }
> }

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