| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
就是wa 怎么也过不了 能想到的例子都试了 !!!求大牛#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *plus(char *a,char *b)
{
char ans[500];
int m[500],n[500],sum[500];
int lena,lenb,l,i;
memset(m,0,sizeof(m));
memset(n,0,sizeof(n));
memset(sum,0,sizeof(sum));
lena=strlen(a);
lenb=strlen(b);
l=lena>lenb?lena:lenb;
for(i=0;i<lena;i++)
{
m[i]=a[lena-i-1]-'0';
}
for (i=0;i<lenb ;i++ )
n[i]=b[lenb-i-1]-'0';
for(i=0;i<l;i++)
{
sum[i]+=m[i]+n[i];
if(sum[i]>9)
{
sum[i]-=10;
sum[i+1]++;
}
}
if(sum[l]>0) l++;
for(i=0;i<l;i++)
{
ans[i]=sum[l-1-i]+'0';
}
ans[l]='\0';
return ans;
}
int cmp(char *a,char *b)
{
int la,lb;
la=strlen(a);
lb=strlen(b);
if(la>lb) return 1;
else if(la<lb) return -1;
else return strcmp(a,b);
}
int main()
{
int ed,st,i,count;
char a[500],b[500];
char fi[1000][500];
fi[0][0]='1';
fi[1][0]='1';
fi[2][0]='2';
fi[0][1]='\0';
fi[1][1]='\0';
fi[2][1]='\0';
for (i=3; i<1000 ; i++)
{
strcpy(fi[i],plus(fi[i-1],fi[i-2]));
}
while(1)
{
count=0;
scanf("%s %s",a,b);
if(strcmp(b,"0")==0) break;
for(i=1; i<1000; i++)
{
if(cmp(fi[i],a)>=0)
{
st=i;
break;
}
}
for(; i<1000; i++)
{
if(cmp(fi[i],b)<=0)
{
count++;
}
}
printf("%d\n",count);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator