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

这个算法有什么问题吗?超时,真是郁闷啊

Posted by ygl6188 at 2011-03-10 15:38:28 on Problem 3070
#include<stdio.h>
#define MAXN 100
int Num[MAXN];
int fabnaci(int n)
{
	int a=0;int b=1;int i=2;int c;
	if(n==0)
		return 0;
	if(n==1)
		return 1;
	while(i<=n)
	{
		c=(a+b)%10000;
		a=b;
		b=c;
		i++;
	}
	return c;
}
		
int main()
{
	int j=0,counter=0;
	do
	{
		scanf("%d",&Num[j]);
		if(Num[j]!=-1)
		{
			j++;
			counter++;
		}
		else
			break;
	}while(1);
	j=0;
	while(j<counter)
		printf("%d\n",fabnaci(Num[j++]));
	
	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