#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
struct node
{
int len;
int num[30000];
node(){len=0;memset(num,0,sizeof(num));}
void xchili(char *in)
{
int llen=strlen(in)-1;
int x=0;
len=(llen+1)/4-1;
if((llen+1)%4)
len++;
int place=0;
int time=1;
for(int i=llen;i>=0;i--)
{
x=x+(in[i]-'0')*time;
time*=10;
if(time==10000)
{
num[place++]=x;
x=0;
time=1;
}
}
if((llen+1)%4)
num[len]=x;
}
node operator *(node &b)
{
node k;
for(int i=0;i<=len;i++)
for(int j=0;j<=b.len;j++)
{
k.num[i+j]+=num[i]*b.num[j];
k.num[i+j+1]+=k.num[i+j]/10000;
k.num[i+j]%=10000;
}
k.len=len+b.len+1;
while(k.num[k.len]==0&&k.len)
k.len--;
return k;
}
node operator +(node &b)
{
node re;
int llen=max(len,b.len);
for(int i=0;i<=llen;i++)
{
re.num[i]=num[i]+b.num[i];
re.num[i+1]+=re.num[i]/10000;
re.num[i]%=10000;
}
re.len=llen;
if(re.num[re.len+1])
re.len++;
return re;
}
};
char a[3000],b[3000];
node work(char *in)
{
}
node ans1,ans2,out;
int main()
{
//cin>>a>>b;
/*scanf("%s",a);
scanf("%s",b);*/
int n;
scanf("%d",&n);
int mode=2;
//scnaf("%d",&mode);
if(mode==1)
{
if(a[0]=='-'&&b[0]!='-')
{
cout<<"-";
//ans1=work(a+1);
ans1.xchili(a+1);
//ans2=work(b);
ans2.xchili(b);
}
if(a[0]!='-'&&b[0]=='-')
{
cout<<"-";
//ans1=work(a);
ans1.xchili(a);
//ans2=work(b+1);
ans2.xchili(b+1);
}
if(a[0]=='-'&&b[0]=='-')
{
//ans1=work(a+1);
ans1.xchili(a+1);
//ans2=work(b+1);
ans1.xchili(b+1);
}
if(a[0]!='-'&&b[0]!='-')
{
//ans1=work(a);
ans1.xchili(a);
//ans2=work(b);
ans2.xchili(b);
}
out=ans1*ans2;
printf("%d",out.num[out.len]);
for(int i=out.len-1;i>=0;i--)
{
/*if(out.num[i]==0&&i!=out.len)
{
cout<<"0000";
continue;
}
if(out.num[i]<10&&i!=out.len)
{
cout<<"000"<<out.num[i];
continue;
}
if(out.num[i]<100&&i!=out.len)
{
cout<<"00"<<out.num[i];
continue;
}
if(out.num[i]<1000&&i!=out.len)
{
cout<<"0"<<out.num[i];
continue;
}
cout<<out.num[i];*/
printf("%04d",out.num[i]);
}
}
if(mode==2)
{
node e,f,c;
e.len=0;e.num[0]=1;
f.len=0;f.num[0]=2;
if(n>=3)
{
for(int i=3;i<=n;i++)
{
c=e+f;
e=f;
f=c;
}
printf("%d",c.num[c.len]);
for(int i=c.len-1;i>=0;i--)
printf("%04d",c.num[i]);
}
if(n==2)
printf("2");
if(n==1)
printf("1");
if(n==0)
printf("1");
}
return 0;
}
转载于:https://www.cnblogs.com/Lance1ot/p/8496677.html