求助:洛谷AC本地RE
查看原帖
求助:洛谷AC本地RE
252549
Iwara楼主2023/7/19 12:05
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e6+5;
struct bignum{
	ll num[MAXN],sz;
	void read(){
		string s;
		cin>>s;
		sz=0;
		ll s_l=s.size(),now=0,p=1;
		for(ll i=s_l-1;i>=0;i--){
			now+=p*(s[i]-'0');
			p*=10;
			if(p==1e10)num[++sz]=now,now=0,p=1;
		}
		num[++sz]=now;
		return;
	}
	void check(){
		for(int i=sz;i>=1;i--){
            if((!num[i])&&i!=1)continue;
            ll L=log10(num[i]);
            if(num[i]==0)L=0;
            if(i!=sz)for(int j=1;j<=10-L-1;j++)cout<<0;
            cout<<num[i];
        }
		cout<<endl;
		return;
	}
	void add_num(bignum oth){
		ll L=max(sz,oth.sz),tmp=0;
		for(int i=1;i<=L;i++){
			tmp=tmp+num[i]+oth.num[i];
			num[i]=tmp%(ll)1e10;
			tmp/=(ll)1e10;
		}
		if(tmp)num[L+1]=tmp,sz=L+1;
		else sz=L;
		return;
	}
}a,b;
ll T;
int main(){
	T=1;
	while(T--){
		a.read();
		b.read();
		a.add_num(b);
		a.check();
	}
	return 0;
} 

我的DEV实在是奇葩

2023/7/19 12:05
加载中...