转载请注明出处:http://blog.csdn.net/u012860063
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1715
5 1 2 3 4 5
1 1 2 3 5
代码如下:
//HDU 1715 #include<cstdio> #include<iostream> #include<cstring> #define N 1002 using namespace std; char Fib[N][N]; int main() { memset(Fib,'0',sizeof(Fib)); // 初始化 Fib[0][0]='0'; Fib[1][0]='1'; Fib[2][0]='1'; int i,j,d=1; for(i = 3 ; i < N ; i++) //大数相加 { d++; int c=0,s; for(j = 0 ; j <= d ; j++) { s=Fib[i-1][j]-'0'+Fib[i-2][j]-'0'+c; c=s / 10; //进位 Fib[i][j] = s%10+'0'; } } int t; //cin>>t; scanf("%d",&t); while(t--) { int n; // cin >> n; scanf("%d",&n); int k=N-1; while(k--) { if(Fib[n][k]!='0') break; //去掉前面的0 } for(i=k;i>=0;i--) printf("%c",Fib[n][i]); //cout<<Fib[n][i]; // cout<<endl; printf("\n"); } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/32960269