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的这个值算上wa了两次,最惨的是因为#“iostream.h"这个头文件搞的我Compile Error了四次我真是菜到底了

Posted by liuwencheng at 2011-01-14 21:30:27 on Problem 2413
新手请指教
#include"stdio.h"
#include"string.h"
char fn[510][150];
void f()//求fn的值
{
	int i,j,sign;
	for(i=0 ; i<510 ; i++)
		memset(fn[i],'0',sizeof(fn[i]));
	fn[1][0]='1';fn[1][1]='\0';
	fn[2][0]='2';fn[2][1]='\0';
	for(i=3 ;  ; i++)
	{
		if( strlen(fn[i-1]) >108)//计算到10的101次
			return;
		for(j=0 ; j<strlen(fn[i-1]) ;j++)//做加法
		{
			if( j < strlen(fn[i-2]) )
				fn[i][j] += fn[i-1][j] + fn[i-2][j] -48;
			else
				fn[i][j] +=fn[i-1][j];
			if( (fn[i][j]-96)/10 )//处理进位
			{
				sign=1;//标志是否进位
				fn[i][j+1]='1';
				fn[i][j]=( (fn[i][j]-96)%10 ) + 48;
			}
			else  { fn[i][j]-=48; sign=0; }
		}
		if(sign)
			fn[i][j+1]='\0';
		else fn[i][j]='\0';
	}
}
int main()
{
	f();
	char a[150],b[150];
	int count;
	int i,j,k,sign,a1,b1;
	while(scanf("%s",a) && scanf("%s",b))
	{
		if(a[0]=='0' && b[0]=='0')
			return 0;
		count=0;
		sign=0;
		a1=strlen(a);
		b1=strlen(b);
		for(i=1 ;  ; i++)
		{
			if( strlen(fn[i])<a1)
				continue;
			if(strlen(fn[i])>b1)//控制结束
				break;
			if( strlen(fn[i]) ==b1)//控制结束
			{
				for(j=strlen(fn[i])-1 , k=0 ; j>=0 ; k++ , j--)//fn与b比较
				{
					if(fn[i][j]<b[k])
					 	break;
					else if(fn[i][j]==b[k])
						continue;
					else {sign =1 ; break;}
				}
			}
			if(sign)//控制结束
				break;
			if( strlen(fn[i]) > a1)
				count++;
			else
			{
				int mm=0;//标志相等的时候
				for(j=strlen(fn[i])-1 , k=0 ; j>=0 ; k++ , j--)//fn与a比较
				{
				//	cout<<fn[i][j]<<"VS"<<a[k]<<endl;
					if(fn[i][j]>a[k])
					{ count++;    mm=0; break;}
					else if(fn[i][j] == a[k])
					{mm=1;	continue; }
					else {mm=0; break;}
				}
				if(mm)
					count++;
			}
		}
		printf("%d\n",count);
	}
	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