Accepted喵 @ 2020-09-11 12:58:17
请问大佬这里的高精度加法怎么写啊,就是把两个代码合成一个 数楼梯unsingned long long代码:
#include<cstdio>
using namespace std;
unsigned long long a[5010];
unsigned long long taijie(int x){
a[0]=0;
a[1]=1;
a[2]=2;
for(int i=2;i<=x;i++) a[i]=a[i-1]+a[i-2];
return a[x];
}
int n;
int main(){
scanf("%d",&n);
printf("%llu",taijie(n));
}
高精加法:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char ac[510],bc[510];
int ai[510]={},bi[510]={},ans[510];
int lena,lenb,lenans,maxab;
void gaojingjiafa(char a1c[510],char b1c[510]){
lena=strlen(a1c),lenb=strlen(b1c);
for(int i=0;i<lena;i++) ai[lena-i-1]=ac[i]-48;
for(int i=0;i<lenb;i++) bi[lenb-i-1]=bc[i]-48;
maxab=lena>lenb?lena:lenb;
for(int i=0;i<maxab;i++){
ans[i]+=ai[i]+bi[i];
if(ans[i]>=10){
ans[i]%=10;
ans[i+1]++;
}
}
for(int i=ans[maxab]==1?maxab:maxab-1;i>=0;i--) printf("%d",ans[i]);
return;
}
int main(){
cin>>ac>>bc;
gaojingjiafa(ac,bc);
}
by Chinese_zjc_ @ 2020-09-11 14:44:46
就直接合并喽
by Accepted喵 @ 2020-10-15 23:41:56
@Chinesezjc 咋搞啊,蒟蒻不懂qwq
by Chinese_zjc_ @ 2020-10-16 07:53:39
开个结构体,结构体维护高精度