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

输入结束判断有问题,还有没有考虑A=B的情况!

Posted by davydc at 2005-12-28 13:10:43 on Problem 1207
In Reply To:为什么是wrong answer啊?请各位帮帮忙! Posted by:870817 at 2005-12-28 12:29:22
> #include <stdio.h>
> #include <math.h>
> void main(){
> 	int a,b,i,k,s=1,t,x,y;
> 	scanf("%d %d",&a,&b);
> 	while(a!=b){
> 		s=1;
> 		if(a>b){x=b;y=a;}
> 		else if(a<b){x=a;y=b;}
> 		for(i=x;i<=y;i++){
> 			k=i;
> 			t=1;
> 			while(k!=1){
> 				if(k%2==0){ k=k/2; t++;}
> 				else{
> 					k=3*k+1;
> 					t++;}
> 			}
> 			if(t>s) s=t;
> 		}
> 		printf("%d %d %d\n",a,b,s);
> 		scanf("%d %d",&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