Calculate a + b and output the sum in standard format — that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

Sample Input
-1000000 9
Sample Output
-999,991

翻译:

计算a+b的和并以“标准”格式输出——即输出的数据必须以逗号分隔成三组(除非不足4位)。

输入:每一个输入文件包含1个测试用例,每一个测试用例包含一对整数 a 和 b,-1000000 <= a, b <= 1000000, a和b用空格分隔。

输出:对于每一个测试用例,你必须输出在一行内按“标准”格式输出 a 和 b 的和。

思路:把 sum 放入 string 中,逐位判断位数下标对3的余数是否等于总长度对3的余数,如果相等并且非最后一位,则在输出该位后输出一个逗号,另需考虑到符号。

代码:


#include <iostream> 
#include <string> 
using namespace std;
int main() 
{
	int a, b;
	string s;
	cin >> a >> b;
	s = to_string(a + b);
	for (int i = 0; i < s.length(); ++i) 
	{
		cout << s[i];
		if (s[i] == '-') continue;
		if ((i + 1) % 3 == s.length() % 3 && i + 1 != s.length()) cout << ",";
	}
	return 0;
}