No丶one @ 2017-04-14 17:43:26
#include<iostream>
#include<cstring>
using namespace std;
int n;
string fa[5001];
string sss(string a,string b)
{
int la,lb,lc,aa[5001]={0},bb[5001]={0};
char c[5001];
la=a.length();
lb=b.length();
for(int i=1;i<=la;++i) aa[i]=a[la-i]-48;
for(int i=1;i<=lb;++i) bb[i]=b[lb-i]-48;
if(la<lb) lc=lb;
else lc=la;
for(int i=1;i<=lc;++i)
aa[i]+=bb[i];
for(int i=1;i<=lc;++i)
{
aa[i+1]+=aa[i]/10;
aa[i]%=10;
}
while(aa[lc+1]==1) lc++;
for(int i=0;i<lc;++i) c[i]=aa[lc-i]+48;
return c;
}
int main()
{
cin>>n;
fa[1]='1';
fa[2]='2';
for(int i=3;i<=n;++i)
{
fa[i]=sss(fa[i-1],fa[i-2]);
}
cout<<fa[n];
}
by AK_Automata @ 2017-04-14 20:02:40
pic=4982
by AK_Automata @ 2017-04-14 20:03:11
by dingchengrui @ 2017-06-02 13:26:54
#include<iostream>
#include<cstring>
using namespace std;
int n;
string fa[5001];
string sss(string a,string b)
{
int la,lb,lc,aa[5001]={0},bb[5001]={0};
char c[5001];
la=a.length();
lb=b.length();
for(int i=1;i<=la;++i) aa[i]=a[la-i]-48;
for(int i=1;i<=lb;++i) bb[i]=b[lb-i]-48;
if(la<lb) lc=lb;
else lc=la;
for(int i=1;i<=lc;++i)
aa[i]+=bb[i];
for(int i=1;i<=lc;++i)
{
aa[i+1]+=aa[i]/10;
aa[i]%=10;
}
while(aa[lc+1]==1) lc++;
for(int i=0;i<lc;++i) c[i]=aa[lc-i]+48;
return c;
}
int main()
{
cin>>n;
fa[0]='0';
fa[1]='1';
fa[2]='2';
for(int i=3;i<=n;++i)
{
fa[i]=sss(fa[i-1],fa[i-2]);
}
cout<<fa[n];
}
试一试,反正经我修改后过了
by dingchengrui @ 2017-06-02 13:29:11
只是加一个fa[0]=‘0’;在cin>>n;前。
0是一个特殊值,那个点就错在0上。
by Heartlessly @ 2017-06-29 10:45:31
by Seas0 @ 2017-07-03 21:29:35
by Seas0 @ 2017-07-03 21:29:52
by Seas0 @ 2017-07-03 21:33:42
by SHDITYR @ 2017-07-12 21:25:29
不是零,是35