题解
2026-02-27 11:36:48
发布于:广东
2阅读
0回复
0点赞
又来发题解了:升级版
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <stdlib.h>
using std::cout;
using std::cin;
using std::vector;
using std::string;
using std::ios;
class Father
{
public:
private:
};
class IO :
public Father
{
public:
template<typename T>
T read()
{
T IN;
cin>>IN;
return IN;
}
template<typename ...T>
void write(T...args)
{
(cout<<...<<args);
}
template<typename ...T>
void writeln(T...args)
{
write(args...,"\n");
}
};
class AB :
public Father
{
private:
string A,B;
IO * io = new IO();
vector<int> add
(
const vector<int>& a,
const vector<int>& b
) {
vector<int> res;
int carry = 0;
int i = 0;
while
(
i < a.size() ||
i < b.size() ||
carry > 0
) {
int sum;
sum = carry;
if
(
i < a.size()
)
sum += a[i];
if
(
i < b.size()
)
sum += b[i];
res.push_back(sum % 10);
carry = sum / 10;
i++;
}
return res;
}
vector<int> stb(
const string& s
) {
vector<int> res;
for (
int i = s.size() - 1;
i >= 0;
i--
) {
res.push_back((s[i] - '0'));
}
return res;
}
public:
AB(
bool YES_RUN_GO,
int argc,
const char* argv[]
){
if(
YES_RUN_GO
){
this->A=io->read<string>(),this->B=io->read<string>();
}
}
void __init__(
bool YES_INIT_GO
){
if(
YES_INIT_GO
){
vector<int> a =
this->stb(
this->A
);
vector<int> b =
this->stb(
this->B
);
vector<int> c =
this->add(
a
,
b
)
;
for(
int i = c.size()-1;
i>=0;
i--
){
io->write(
int(c[i])
);
}
io->writeln();
}
}
};
static bool AB_PROBLEM_YES=true;
int main(int argc,
const char* argv[]
){
ios::sync_with_stdio(0);
cin.tie(0);
AB * ab = new AB(AB_PROBLEM_YES,
argc,
argv);
ab->__init__(AB_PROBLEM_YES);
delete ab;
}
这里空空如也




有帮助,赞一个