大数相加
#include <bits/stdc++.h>
using namespace std;
vector<int> getAdd(vector<int>& A,vector<int>& B)
{
if(A.size()<B.size()) return getAdd(B,A);
vector<int> C;
int cf=0;
for (int i=0;i<A.size();++i){
cf+=A[i];
if(i<B.size()) cf+=B[i];
C.push_back(cf%10);
cf/=10;
}
if (cf) C.push_back(1);
return C;
}
int main()
{
string a,b;
vector<int> A,B;
cin>>a>>b;
for (int i=a.size()-1;i>=0;i--) A.push_back(a[i]-'0');
for (int i=b.size()-1;i>=0;i--) B.push_back(b[i]-'0');
auto C=getAdd(A,B);
for (int i=C.size()-1;i>=0;i--) printf("%d",C[i]);
return 0;
}
大数相减
#include <bits/stdc++.h>
using namespace std;
bool cmp(vector<int> & A,vector<int>& B)
{
if(A.size()!=B.size()) return A.size()<B.size