Submission #15133

# Submission time Handle Problem Language Result Execution time Memory
15133 2015-07-11T13:41:30 Z ddaafftt 꼬마 정민 (kriii3_RR) C++14
20 / 20
0 ms 1720 KB
#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;
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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