Update Source File

This commit is contained in:
Hmtsai 2023-11-19 13:30:04 +08:00
parent 587ad6a38a
commit 7dcbce15f6
2 changed files with 35 additions and 0 deletions

BIN
src/algorithm/plus/plus Executable file

Binary file not shown.

View File

@ -0,0 +1,35 @@
#include <cstring>
#include <iostream>
using namespace std;
void myplus(int list1[], int list2[], int list1length, int list2length,
int *count) {
for (int i = 1, x = 0; i <= max(list1length, list2length); i++) {
count[i] = list1[i] + list2[i];
x = count[1] / 10;
count[i] %= 10;
i++;
}
}
void init() {
string snum1, snum2;
cin >> snum1 >> snum2;
int inum1[snum1.size()], inum2[snum2.size()];
for (int i = 0; i < snum1.size(); i++) {
inum1[i] = snum1.c_str()[i] - '0';
}
for (int i = 0; i < snum2.size(); i++) {
inum2[i] = snum2.c_str()[i] - '0';
}
int count[max(snum1.size(), snum2.size()) + 1];
myplus(inum1, inum2, snum1.size(), snum2.size(), count);
for (int i = 0; i < max(snum1.size(), snum2.size()) + 1; i++) {
cout << count[i];
}
}
int main() {
init();
return 0;
}