Ravener @ 2024-02-24 19:21:29
不能正常输出结果
#include<bits/stdc++.h>
using namespace std;
void input(string a,int lena,int x[])
{
for(int i=0;i<lena;i++)
{
x[i]=a[lena-i]-'0';
}
}
void output(string a,int lena,int x[])
{
for(int i=0;i<lena;i++)
{
a[i]=x[lena-i]+'0';
}
}
void jia(string a,string b,string c,int lena,int lenb,int lenc)
{
int n=0;
int x[1005],y[1005],z[1005];
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(z,0,sizeof(z));
input(a,lena,x);
input(b,lenb,y);
lenc=max(lena,lenb)+1;
for(int i=0;i<=lenc;i++)
{
z[i]=x[i]+y[i];
n=z[i]/10;
z[i]%=10;
}
while(z[lenc]==0) --lenc;
output(c,lenc,z);
}
int main()
{
int n,lena=1,lenb=1,lenc=1;
string a="1",b="1",c="0";
cin>>n;
if(n==0) cout<<"0";
else if(n==1) cout<<"1";
else
{
for(int i=1;i<n;i++)
{
if(i%3==1) jia(a,b,c,lena,lenb,lenc);
else if(i%3==2) jia(b,c,a,lenb,lenc,lena);
else jia(c,a,b,lenc,lena,lenb);
}
if(n%3==1) cout<<b;
else if(n%3==2) cout<<c;
else cout<<a;
}
}
by Ravener @ 2024-02-24 19:23:04
而且超时(悲
by 11514zbs @ 2024-02-24 19:23:19
斐波那契数列,屑屑
by 11514zbs @ 2024-02-24 19:23:33
@Ravener
by Ravener @ 2024-02-24 19:24:49
@11514zbs ?
第46~49行就是啊
by Ravener @ 2024-02-24 19:28:57
主要是那个加法直接没法运行