标签:
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
1 #include<cstring> 2 #include<cstdio> 3 #include<iostream> 4 5 6 using namespace std; 7 8 char s[205][2000]; //字符数组,存储两百个大数 9 10 void ADD() 11 { 12 strcpy(s[1],"1"); 13 strcpy(s[2],"2"); //赋初值 14 for(int k=3;k<=200;k++) 15 { 16 char c[2000];//倒序 储存当前结果 17 int p=0,l=0; 18 for(int i=strlen(s[k-1])-1,j=strlen(s[k-2])-1;i>=0||j>=0;i--,j--) //取末尾字符 向前相加 19 { 20 if(i>=0&&j>=0) c[l]=s[k-1][i]+s[k-2][j]-‘0‘+p; 21 else if(i>=0) c[l]=s[k-1][i]+p; 22 else if(j>=0) c[l]=s[k-2][j]+p; 23 //字符形式存储 24 if(c[l]>‘9‘) p=1,c[l]-=10; 25 else p=0; 26 l++; 27 } 28 if(p) c[l++]=‘1‘; 29 c[l]=‘\0‘; 30 31 for(int i=0,j=strlen(c)-1;i<j;i++,j--) {char a;a=c[i];c[i]=c[j];c[j]=a;} //将数组c倒过来 表示当前相加结果 32 strcpy(s[k],c); //存储到结果s中 33 34 } 35 } 36 37 int main() 38 { 39 ADD();//打表 40 int T; 41 cin>>T; 42 while(T--) 43 { 44 char str[205]; 45 cin>>str; 46 int n=strlen(str); 47 cout<<s[n]<<endl; 48 } 49 }
标签:
原文地址:http://www.cnblogs.com/wsaaaaa/p/4287841.html