hoj 1533 Fibonacci Numbers
2012-03-30 14:53
295 查看
http://acm.hit.edu.cn/hoj/problem/view?id=1533
用字符串表示整数,进行大数加法运算
用字符串表示整数,进行大数加法运算
/*This Code is Submitted by billforum for Problem 1533 at 2012-03-30 14:50:02*/ #include <iostream> #include <string.h> #include <stdio.h> #include <stack> using namespace std; int main() { string t1,t2,t; int z; int num; while(scanf("%d",&num)!=EOF) { if(num==1||num==2) { printf("1\n"); } else { t1="1"; t2="1"; for(int k=3;k<=num;k++) { int i,j; z=0; t=""; for(i=t1.length()-1,j=t2.length()-1;i>=0;i--,j--) { t+=(char)((t1[i]-48+t2[j]-48+z)%10+48); z=(t1[i]-48+t2[j]-48+z)/10; } for(i=j;i>=0;i--) { t+=(char)((t2[i]-48+z)%10+48); z=(t2[j]-48+z)/10; } if(z>0) { t+=(char)(z+48); } t1=""; t1=t2; t2=""; for(int ii=t.length()-1;ii>=0;ii--) t2+=t[ii]; } cout<<t2<<endl; } } return 0; }
相关文章推荐
- HOJ-1011 的一些感想
- hoj 1097
- HOJ 2544 最短路
- hoj 2275 Number sequence 树状数组解法
- hoj1058 Number Triangles
- HOJ—Generalized Fibonacci
- hoj 1067 Rails //poj1363 Rails 栈的简单应用
- 【1002 HOJ】A+B+C
- [割点问题]HOJ 12307 Disconnected Pair
- HOJ---12363 Robots on a grid [DP+BFS()]
- Count prime hoj 区间求素数个数(大范围)
- Network of Schools hoj&poj 强连通分量的应用 经典题!
- Square DFS poj&hoj
- hoj 2430 树状数组 简单题
- HOJ 2934 Simple Math Question
- HOJ 2314 Stamps
- HOJ 2016 Conic Distance
- HOJ 1649 Count on Canton
- HOJ 1446 Binomial Showdown
- HOJ 1016 Joseph's problem I 树状数组求第K大