| ||||||||||
| 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了N遍,请大牛们帮忙找一下哪儿错了#include<stdio.h>
#include<string.h>
#define MAX 1000
char str[800][300];
char a1[1100],b1[1100];
void add(char *str1,char *str2,char *c)
{
int len1,len2;
char a[MAX],b[MAX];
int maxlen;
int carry;
strcpy(a,str1);
strcpy(b,str2);
len1=strlen(a);
len2=strlen(b);
for(int i=0;i<len1;i++)
a[i]-='0';
for(int i=0;i<len2;i++)
b[i]-='0';
maxlen=len1>len2?len1:len2;
carry=0;
for(int i=maxlen;i>=0;i--)
{
if(len1>0&&len2>0)
{
c[i]=(a[len1-1]+b[len2-1]+carry)%10+'0';
carry=(a[len1-1]+b[len2-1]+carry)/10;
}
else if(len1>0&&len2<=0)
{
c[i]=(a[len1-1]+carry)%10+'0';
carry=(a[len1-1]+carry)/10;
}
else if(len2>0&&len1<=0)
{
c[i]=(b[len2-1]+carry)%10+'0';
carry=(b[len2-1]+carry)/10;
}
else c[i]=carry+'0';
len1--,len2--;
}
c[maxlen+1]='\0';
if(c[0]=='0') strcpy(c,c+1);
}
int comp(char *str1,char *str2)
{
int len1=strlen(str1);
int len2=strlen(str2);
if(len1>len2||(len1==len2&&strcmp(str1,str2)>=0)) return 1;
else return 0;
}
int cmp(char *c)
{
if(comp(c,a1)&&comp(b1,c)) return 1;
else if(comp(c,b1)) return 0;
else return -1;
}
int main()
{
strcpy(str[1],"1");
strcpy(str[2],"2");
for(int i=3;i<800;i++)
{
add(str[i-1],str[i-2],str[i]);
}
while(scanf("%s %s",a1,b1))
{
int sum=0;
if(strcmp(a1,"0")==0&&strcmp(b1,"0")==0) break;
for(int i=1;i<800;i++)
{
if(cmp(str[i])==1) sum++;
if(cmp(str[i])==0) break;
}
printf("%d\n",sum);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator