您的位置:首页 > 其它

hdu 1250 大数相加并用数组储存

2013-04-12 21:55 1011 查看
#include<iostream>
using namespace std;
int main()
{
int a[5][2010];
int i,j;
int temp; //储存进位数
int n,len,k;
while(cin>>n)
{
memset(a,0,sizeof(a));
a[0][0]=a[1][0]=a[2][0]=a[3][0]=1;
len=1;
for(i=4;i<n;i++)
{
temp=0;
for(j=0;j<len;j++)
{
temp+=a[(i-4)%5][j]+a[(i-3)%5][j]+a[(i-2)%5][j]+a[(i-1)%5][j];
a[i%5][j]=temp%10;
temp/=10;
}
while(temp) //注意
{
a[i%5][j++]=temp%10;
temp/=10;
}
len=j;
}
len--;
for(;len>=0;len--)
cout<<a[(n-1)%5][len];
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数组 acm 大数相加