用了一个下午终于AC了,不过代码很笨拙,不过还是很有成就感~~~~~~~~
不过这个大数相加处理得不怎么好,注释就不上了,代码感觉不怎么好,有待学习~!!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
char s1[1000],s2[1000],sum[1000][1000];
int n,m,len,len1,len2,i,*p,k=1000,w;
n=3;
strcpy(sum[1],"1");
strcpy(sum[2],"1");
strcpy(s1,"1");
strcpy(s2,"1");
while(k--)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
while(n<=k)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
len1=strlen(s1),len2=strlen(s2);
len=len2+2;
p=(int *)malloc(len*sizeof(int));
for(i=0;i<len;i++)
p[i]=0;
if(len1==len2)
for(i=len2;i>0;i--)
*(p+i)=(*(s1+i-1)-48)+(*(s2+i-1)-48);
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(i=len2;i>1;i--)
*(p+i)=(*(s1+i-2)-48)+(*(s2+i-1)-48);
*(p+i)=(*(s2+i-1))-48;
}
for(i=len2;i>0;i--)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
*(p+i)+=*(p+i+1)/10;
*(p+i-1)+=*(p+i)/10;
*(p+i)=*(p+i)%10;
}
strcpy(s1,s2);
if(p[0]==0)
for(i=0;i<len2;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
s2[i]=*(p+i+1)+'0';
}
else
for(i=0;i<=len2;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
s2[i]=*(p+i)+'0';
}
s2[i]='\0';
strcpy(sum[n],s2);
n++;
}
}
while(scanf("%d",&w)!=EOF)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(i=0;i<w;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%d",&m);
if(m==1||m==2)
printf("1\n");
else
puts(sum[m]);
}
}
return 0;
}
![](/Images/OutliningIndicators/None.gif)