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:Why is it Wrong answer

Posted by 20121181jj at 2014-01-21 23:33:23 on Problem 1207
In Reply To:Why is it Wrong answer? Posted by:20121181jj at 2014-01-21 23:22:02
> #include<iostream>
> #include<stdio.h>
> long num;
> long f(long n){	
>     num++;
> 	if(n==1) return num;
> 	else if(n%2==1) return f(3*n+1);
> 	else return f((int)n/2);
> }
> using namespace std;
> int main(){
> 	long i,j;
> 	while(scanf("%d%d",&i,&j)!=EOF&&i>0&&i<10000&&j>0&&j<10000){
> 		if(i>j) swap(i,j);
> 		num=0;
> 		f(i);
> 		long max=num;
> 		for(long k=i+1;k<=j;k++){
> 			num=0;
> 			f(k);
> 			max=max>num? max:num;
> 		}
> 	    cout<<i<<' '<<j<<' '<<max<<endl;
> 	}
> 	return 0;

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