P1601 A+B Problem(高精)
作者:互联网
题目链接
题目思路
模板
题目代码
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> a, b;
vector<int> add(vector<int> &a, vector<int> &b)
{
vector<int> c;
int t = 0;
for(int i = 0; i < a.size() || i < b.size(); i ++ )
{
if(i < a.size()) t += a[i];
if(i < b.size()) t += b[i];
c.push_back(t % 10);
t /= 10;
}
if(t == 1) c.push_back(1);
return c;
}
int main()
{
string 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 = add(a, b);
for(int i = c.size() - 1; i >= 0; i -- ) cout << c[i];
return 0;
}
标签:int,back,vector,高精,push,P1601,Problem,include,size 来源: https://www.cnblogs.com/vacilie/p/15983460.html