标签:
只想说这个模板好啊
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; char s[205][200]; void add(char a[],char b[],char back[]) { int i,j,k,up,x,y,z,l; char *c; if (strlen(a)>strlen(b)) l=strlen(a)+2; else l=strlen(b)+2; c=(char *) malloc(l*sizeof(char)); i=strlen(a)-1; j=strlen(b)-1; k=0;up=0; while(i>=0||j>=0) { if(i<0) x=‘0‘; else x=a[i]; if(j<0) y=‘0‘; else y=b[j]; z=x-‘0‘+y-‘0‘; if(up) z+=1; if(z>9) {up=1;z%=10;} else up=0; c[k++]=z+‘0‘; i--;j--; } if(up) c[k++]=‘1‘; i=0; c[k]=‘\0‘; for(k-=1;k>=0;k--) back[i++]=c[k]; back[i]=‘\0‘; } void pre(){ strcpy(s[1],"1"); strcpy(s[2],"2"); //s[2][] = "2"; for(int i = 3; i<=201; i++) { add(s[i-1],s[i-2],s[i]); } } int main() { pre(); int n; while(scanf("%d",&n)!=EOF){ if(n == 0) printf("\n"); else printf("%s\n",s[n]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/littlepear/p/5493121.html