1817:A+B

Question B: A+B

Time Limit: 1 Sec Memory Limit: 32 MB
Commits: 760 Resolved: 426
[ Commit ][ Status ][ Discussion Board ][Proposer:ExternalImport]

Topic description

Given two integers A and B, their representation is: starting from the one digit, separated by commas "," every three digits.
Now please calculate the result of A+B and output it in normal form.

enter

The input contains multiple sets of data data, each set of data occupies a row, consisting of two integers A and B (-10^9 < A, B < 10^9).

output

Please calculate the result of A+B and output it in normal form, each set of data occupies one line.

sample input

-234,567,890 123,456,789
1,234 2,345,678

Sample output

-111111101
2346912
#include<iostream>
#include<string>
using namespace std;
int main() {
	string str1, str2;
	while (cin >> str1 >> str2) {
		int x = 0, y = 0, flag = 1;
		for (int i = 0; i < str1.length(); i++) {
			if (str1[i] == ',')
				continue;
			if (str1[i] == '-') {
				flag = -1;
				continue;
			}
			x *= 10;
			x += str1[i] - '0';
		}
		x *= flag;
		flag = 1;
		for (int i = 0; i < str2.length(); i++) {
			if (str2[i] == ',')
				continue;
			if (str2[i] == '-') {
				flag = -1;
				continue;
			}
			y *= 10;
			y += str2[i] - '0';
		}
		y *= flag;
		cout << x + y << endl;
	}
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325773987&siteId=291194637