48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
|
//#include <iostream>
|
||
|
//#include <vector>
|
||
|
//#include <string>
|
||
|
//
|
||
|
//using namespace std;
|
||
|
//
|
||
|
//string highPrecisionAdd(const string& s1, const string& s2) {
|
||
|
// int la = s1.length();
|
||
|
// int lb = s2.length();
|
||
|
// int lc = max(la, lb);
|
||
|
// vector<int> a(lc + 1, 0); // +1 to handle carry over
|
||
|
// vector<int> b(lc + 1, 0);
|
||
|
// vector<int> c(lc + 1, 0);
|
||
|
//
|
||
|
// for (int i = 0; i < la; i++) {
|
||
|
// a[i] = s1[la - i - 1] - '0'; // reverse order
|
||
|
// }
|
||
|
// for (int i = 0; i < lb; i++) {
|
||
|
// b[i] = s2[lb - i - 1] - '0'; // reverse order
|
||
|
// }
|
||
|
//
|
||
|
// for (int i = 0; i < lc; i++) {
|
||
|
// c[i] += a[i] + b[i];
|
||
|
// if (c[i] >= 10) {
|
||
|
// c[i + 1] += c[i] / 10;
|
||
|
// c[i] %= 10;
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// // handle last carry
|
||
|
// if (c[lc] > 0) lc++;
|
||
|
//
|
||
|
// string result;
|
||
|
// bool leadingZero = true;
|
||
|
// for (int i = lc - 1; i >= 0; i--) {
|
||
|
// if (leadingZero && c[i] == 0) continue;
|
||
|
// leadingZero = false;
|
||
|
// result.push_back(c[i] + '0');
|
||
|
// }
|
||
|
//
|
||
|
// return result.empty() ? "0" : result;
|
||
|
//}
|
||
|
//
|
||
|
//int main() {
|
||
|
// cout << highPrecisionAdd("5555", "50") << endl; // Expected output: 100
|
||
|
// return 0;
|
||
|
//}
|