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

各位牛人帮帮忙啊,我被wa7次了

Posted by fs94007 at 2006-12-09 21:39:04
我的原码:
测试数据都对,就是wa
#include<stdio.h>
int cl(int n)
{
	int i=n,p=1;
	while(i!=1)
	{
		if(i%2==0)
			i/=2;
		else
			i=3*i+1;
		p++;
	}
	return p;
}
void comp(int t,int n)
{
	int i,max=0;
	printf("%i %i ",t,n);
	if(t>n)
	{
		t+=n;
		n=t-n;
		t=t-n;
	}
	for(i=t;i<=n;i++)
	{
		if(cl(i)>=max)
			max=cl(i);
	}
	printf("%i\n",max);
}
void main()
{
	int n[4],i=0,t[4];
	while((scanf("%i%i",&n[i],&t[i]))==2)
	{
		i++;
		if(i==4)
			break;
	}
	for(i=0;i<=3;i++)
		comp(n[i],t[i]);
}


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