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

 
 
  1. #include<iostream> 
  2. using namespace std; 
  3. int main() 
  4.     int a[5][2010]; 
  5.     int i,j; 
  6.     int temp; //储存进位数
  7.     int n,len,k; 
  8.     while(cin>>n) 
  9.     { 
  10.         memset(a,sizeof(a)); 
  11.         a[0][0]=a[1][0]=a[2][0]=a[3][0]=1; 
  12.         len=1; 
  13.         for(i=4;i<n;i++) 
  14.         { 
  15.             temp=0; 
  16.             for(j=0;j<len;j++) 
  17.             { 
  18. temp+=a[(i-4)%5][j]+a[(i-3)%5][j]+a[(i-2)%5][j]+a[(i-1)%5][j]; 
  19.                 a[i%5][j]=temp%10; 
  20.                 temp/=10; 
  21.             } 
  22.             while(temp) //注意
  23.             { 
  24.                 a[i%5][j++]=temp%10; 
  25.                 temp/=10; 
  26.             } 
  27.             len=j; 
  28.         } 
  29.         len--; 
  30.         for(;len>=0;len--) 
  31.         cout<<a[(n-1)%5][len]; 
  32.         cout<<endl; 
  33.     } 
  34.     return 0; 

相关文章

自1998年我国取消了福利分房的政策后,房地产市场迅速开展蓬...
文章目录获取数据查看数据结构获取数据下载数据可以直接通过...
网上商城系统MySql数据库设计
26个来源的气象数据获取代码
在进入21世纪以来,中国电信业告别了20世纪最后阶段的高速发...