转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents
找规律,前两个数的和等于后一个数的值;
其实就是大菲波数;
代码如下:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #include<cstdio> #include<cstring> void fan(char s[]) { char t; int i,j; for(i = 0,j = strlen(s)-1;i <= j;i++,j--) { t=s[i];s[i]=s[j];s[j]=t; } } char ans[10047][4000]; int main() { int i,j,n,p=0,g=0,h=1,k,l; char x[4000],y[4000],z[4000]; strcpy(ans[1],"1"); strcpy(ans[2],"3"); strcpy(ans[3],"4"); for(int mm = 4 ; mm<= 10000; mm++) { memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); p=0; strcpy(x,ans[mm-1]); strcpy(y,ans[mm-2]); fan(x);fan(y); k=strlen(x); l=strlen(y); for(i = 0;i < k || i< l;i++ ) { if(i < k && i < l ) z[i]=x[i]+y[i]+ p-'0'; else if(i < k && i >= l) z[i]=x[i]+p; else if(i >= k && i < l) z[i]=y[i]+p; if(z[i]>'9') { z[i]-=10; p=1; } else p=0; } if(p) z[i++]='1'; z[i]='\0'; fan(x);fan(y);fan(z); strcpy(ans[mm],z); } while(~scanf("%d",&n)) { printf("%s",ans[n]); printf("\n"); } return 0; }
UVALive 6270 Edge Case(找规律,大数相加),布布扣,bubuko.com
UVALive 6270 Edge Case(找规律,大数相加)
原文:http://blog.csdn.net/u012860063/article/details/36905379