| ||||||||||
| 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 | |||||||||
谁能帮帮我看看程序哪里错了#include<stdio.h>
#include<string.h>
int num[110];
char a[110],b[110];
int n,m;
int init()
{
char ch;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
n=1;
while(1)
{
scanf("%c",&ch);
if(ch!=' ')
{
a[n]=ch;
n++;
}
else break;
}
m=1;
while(1)
{
scanf("%c",&ch);
if(ch!='\n')
{
b[m]=ch;
m++;
}
else break;
}
n--;
m--;
if(n==1&&m==1&&a[n]=='0'&&b[m]=='0')
return 0;
return 1;
}
int comp(int s[])
{
int i;
if(s[0]==n)
{
for(i=s[0];i>=1;i--)
{
if(s[i]>(a[n-i+1]-'0')) break;
if(s[i]<(a[n-i+1]-'0')) return 0;
}
}
if(s[0]==m)
{
for(i=s[0];i>=1;i--)
{
if(s[i]<(b[m-i+1]-'0')) break;
if(s[i]>(b[m-i+1]-'0')) return 0;
}
}
return 1;
}
int cal()
{
int fi1[110],fi2[110],fi3[110];
int i,judge,max,number=0;
memset(fi1,0,sizeof(fi1));
memset(fi2,0,sizeof(fi2));
memset(fi3,0,sizeof(fi3));
fi1[0]=1;
fi2[0]=1;
fi1[1]=1;
fi2[1]=2;
if(n==1)
number+=(comp(fi1)+comp(fi2));
while(1)
{
max=fi2[0];
for(i=1;i<=max;i++)
{
fi3[i+1]+=(fi1[i]+fi2[i])/10;
fi3[i]+=(fi1[i]+fi2[i])%10;
}
if(fi3[max+1]==1)
fi3[0]=max+1;
else
fi3[0]=max;
if(fi3[0]>m)
return number;
if(fi3[0]>=n&&fi3[0]<=m)
{
judge=comp(fi3);
number+=judge;
}
memcpy(fi1, fi2, sizeof(fi1));
memcpy(fi2, fi3, sizeof(fi2));
memset(fi3,0,sizeof(fi3));
}
}
int main()
{
int i,j;
i=1;
while(1)
{
j=init();
if(j==0) break;
num[i]=cal();
i++;
}
for(j=1;j<i;j++)
printf("%d\n",num[j]);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator