本帖最后由 jhq999 于 2022-10-3 13:43 编辑
#include<iostream>
#include<cstring>
using namespace std;
struct BigInt{
int a[200];
int len;
BigInt(){
for(int i=0;i<200;i+=1)a[i]=0;//////////////
}
void save(string x) {
len = x.length();
int i=0;
for(i=0; i<x.length(); ++i) {
a[200-x.length()+i] = x.c_str()[i]-'0';
}
}
BigInt operator+(BigInt& other) {///////////////////
BigInt c;
c.len = max(this->len, other.len) + 1;
for(int i=199; i>c.len; --i) {
c.a[i]+=a[i]+other.a[i];
if(c.a[i]>9)c.a[i-1]+=1,c.a[i]%=10;//////////////////
}
return c;
}
friend ostream &operator << (ostream Out, const BigInt &p) {
for(int i=199; i>199-p.len; --i) {
Out << p.a[i];
}
}
};
BigInt input() {
string temp1; cin>>temp1;
BigInt temp2; temp2.save(temp1);
return temp2;
}
int main()
{
BigInt a = input(), b = input();
BigInt c=a+b;
for(int i=200-c.len;i<200;i+=1)cout<<c.a[i];////////////////
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
struct BigInt{
char a[200];
int len;
BigInt(){
for(int i=0;i<200;i+=1)a[i]=0;
}
void save(string x) {
len = x.length();
int i=0;
for(i=0; i<x.length(); ++i) {
a[199-x.length()+i] = x.c_str()[i]-'0';
}
}
BigInt operator+(BigInt& other) {
BigInt c;
c.len = max(this->len, other.len);
int i;
for(i=198; i>=199-c.len; --i) {
c.a[i]+=a[i]+other.a[i];
if(c.a[i]>9)c.a[i-1]+=1,c.a[i]%=10;
c.a[i]+='0';
}
if(c.a[i])c.a[i]+='0',c.len+=1;
return c;
}
friend ostream &operator << (ostream Out, const BigInt &p) {
for(int i=199; i>199-p.len; --i) {
Out << p.a[i];
}
}
};
BigInt input() {
string temp1; cin>>temp1;
BigInt temp2; temp2.save(temp1);
return temp2;
}
int main()
{
BigInt a = input(), b = input();
BigInt c=a+b;
cout<<c.a+(199-c.len);
//for(int i=200-c.len;i<200;i+=1)cout<<c.a[i];
return 0;
}
|