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 0705020329 at 2009-10-15 15:17:58 on Problem 2413
#include<iostream>
#include<string.h>
using namespace std;
char  num[750][300];
void add(char *a,char *b,char *c)
{
	int lena=strlen(a),lenb=strlen(b),i;
	int t=0;
	for(i=0;i<lena;i++)
	{
		t=t+a[i]-'0'+b[i]-'0';
		c[i]=t%10+'0';
		t=t/10;
	}
	while(i<lenb)
	{
		t=t+b[i]-'0';
		c[i]=t%10+'0';
		t=t/10;
		i++;
	}
	while(t)
	{
		c[i]=t%10+'0';
		i++;
		t=t/10;
	}
  c[i]='\0';
}
void count()
{
	int i;
	num[0][0]='1',num[1][0]='2';
	for(i=2;i<750;i++)
	{
		add(num[i-2],num[i-1],num[i]);
	}
}
int cmp(char *a,char *b)
{
	int i,t=0;
	if(strlen(b)<strlen(a))
		return -1;
	if(strlen(b)>strlen(a))
		return 1;
	if(strlen(a)==strlen(b))
	{
		for(i=strlen(a)-1;i>=0;i--)
		{
			if(a[i]-'0'>b[t]-'0')
				return -1;
			else if(a[i]-'0'<b[t]-'0')
				return 1;
			else
				;
			t++;
		}
	}
	return 0;
}
int findmax(char *a,char *b)
{
	int i,sum=0;
	for(i=0;i<750;i++)
	{
		if(cmp(a,num[i])>=0&&cmp(num[i],b)>=0)
		{
			sum++;
		}
	}
    return sum;
}
int main()
{
	char a[200],b[200];
	count();
	while(scanf("%s%s",a,b))
	{
	    if(a[0]=='0'&&b[0]=='0')
		    return 0;
	    printf("%d\n",findmax(a,b));
	}
	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