Reprint please indicate the source: http://blog.csdn.net/u012860063? Viewmode = Contents
Find the rule. The sum of the first two numbers is equal to the value of the last one;
In fact, it is the number of maifo;
The Code is as follows:
#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;}