'commit'
This commit is contained in:
26
TangDou/AcWing/HighPrecision/Backup/791_add1.cpp
Normal file
26
TangDou/AcWing/HighPrecision/Backup/791_add1.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 100010;
|
||||
int a[N], al;
|
||||
int b[N], bl;
|
||||
|
||||
void add(int a[], int &al, int b[], int &bl) {
|
||||
int t = 0;
|
||||
al = max(al, bl);
|
||||
for (int i = 1; i <= al; i++) {
|
||||
t += a[i] + b[i];
|
||||
a[i] = t % 10;
|
||||
t /= 10;
|
||||
}
|
||||
if (t) a[++al] = 1;
|
||||
}
|
||||
int main() {
|
||||
string x, y;
|
||||
cin >> x >> y;
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[++al] = x[i] - '0';
|
||||
for (int i = y.size() - 1; i >= 0; i--) b[++bl] = y[i] - '0';
|
||||
add(a, al, b, bl);
|
||||
for (int i = al; i; i--) printf("%d", a[i]);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user