-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from AlgoLeadMe/17-oesnuj
17-oesnuj
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
string Add(string str1, string str2) | ||
{ | ||
string result = ""; | ||
int i = str1.size() - 1; | ||
int j = str2.size() - 1; | ||
int carry = 0; | ||
while (i >= 0 || j >= 0 || carry > 0) | ||
{ | ||
int num1 = 0, num2 = 0; | ||
if (i >= 0) | ||
num1 = str1[i--] - '0'; | ||
if (j >= 0) | ||
num2 = str2[j--] - '0'; | ||
|
||
int sum = num1 + num2 + carry; | ||
carry = sum / 10; | ||
result = to_string(sum % 10) + result; | ||
} | ||
return result; | ||
} | ||
|
||
int main() | ||
{ | ||
string a, b; | ||
cin >> a >> b; | ||
cout << Add(a, b); | ||
return 0; | ||
} |