-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15353.cpp
More file actions
48 lines (46 loc) · 691 Bytes
/
15353.cpp
File metadata and controls
48 lines (46 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 15353. 큰 수 A+B (2)
// 2019.10.24
// 수학
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string a, b;
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
if (a.size() > b.size())
{
swap(a, b);
}
string ans = "";
int size = b.size() - a.size();
for (int i = 0; i < size; i++)
{
a += '0';
}
int carry = 0;
for (int i = 0; i < b.size(); i++)
{
int tmp = (a[i] - '0') + (b[i] - '0') + carry;
if (tmp >= 10)
{
tmp -= 10;
carry = 1;
}
else
{
carry = 0;
}
ans+=(tmp+'0');
}
if (carry == 1)
{
ans += '1';
}
reverse(ans.begin(), ans.end());
cout << ans <<endl;
return 0;
}