#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string s1, s2, s3;
string s, l;
string result;
string result2;
int sub;
char c = '0';
int carry = 0;
cin >> s1 >> s2 >> s3;
s = (s1.size() > s2.size() ? s2 : s1);
l = (s1.size() > s2.size() ? s1 : s2);
sub = l.size() - s.size();
for (int i = s.size() - 1; i >= 0; --i)
{
c = (l[i + sub] - '0') + (s[i] - '0') + carry;
if (10 <= c)
carry = 1;
else
carry = 0;
result.insert(0, 1, (c % 10) + '0');
}
for (int i = sub - 1; i >= 0; --i)
{
c = (l[i] - '0') + carry;
if (10 <= c)
carry = 1;
else
carry = 0;
result.insert(0, 1, (c % 10) + '0');
}
if (1 == carry)
result.insert(0, 1, '1');
carry = 0;
s = (result.size() > s3.size() ? s3 : result);
l = (result.size() > s3.size() ? result : s3);
sub = l.size() - s.size();
for (int i = s.size() - 1; i >= 0; --i)
{
c = (l[i + sub] - '0') + (s[i] - '0') + carry;
if (10 <= c)
carry = 1;
else
carry = 0;
result2.insert(0, 1, (c % 10) + '0');
}
for (int i = sub - 1; i >= 0; --i)
{
c = (l[i] - '0') + carry;
if (10 <= c)
carry = 1;
else
carry = 0;
result2.insert(0, 1, (c % 10) + '0');
}
if (1 == carry)
result2.insert(0, 1, '1');
cout << result2;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1720 KB |
Output is correct |
2 |
Correct |
0 ms |
1720 KB |
Output is correct |
3 |
Correct |
0 ms |
1720 KB |
Output is correct |
4 |
Correct |
0 ms |
1720 KB |
Output is correct |
5 |
Correct |
0 ms |
1720 KB |
Output is correct |
6 |
Correct |
0 ms |
1720 KB |
Output is correct |
7 |
Correct |
0 ms |
1720 KB |
Output is correct |
8 |
Correct |
0 ms |
1720 KB |
Output is correct |
9 |
Correct |
0 ms |
1720 KB |
Output is correct |
10 |
Correct |
0 ms |
1720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1720 KB |
Output is correct |
2 |
Correct |
0 ms |
1720 KB |
Output is correct |
3 |
Correct |
0 ms |
1720 KB |
Output is correct |
4 |
Correct |
0 ms |
1720 KB |
Output is correct |
5 |
Correct |
0 ms |
1720 KB |
Output is correct |
6 |
Correct |
0 ms |
1720 KB |
Output is correct |
7 |
Correct |
0 ms |
1720 KB |
Output is correct |
8 |
Correct |
0 ms |
1720 KB |
Output is correct |
9 |
Correct |
0 ms |
1720 KB |
Output is correct |
10 |
Correct |
0 ms |
1720 KB |
Output is correct |