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 Specification:

Each input file contains one test case. Each case contains a pair of integers a and b where $$-10^{6} \leq a, b \leq 10^{6} $$
. The numbers are separated by a space.

Output Specification:

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且以标准输出–每三个为一组(除非少于四个数)

输入规范:

每个输入文件包含一个测试例子,每个例子包含一对整数a和b,且$$ -10^{6} \leq a, b \leq 10^{6} $$。数字以空格分隔

输出规范:

对于每个测试例子,你应该输出a和b的和在一行,且和必须用标准模式输出

示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
//将a+b转成string
string s = to_string(a + b);
int len = s.length();
for (int i = 0; i < len; i++) {
cout << s[i];
//遇到负号跳过
if (s[i] == '-')
continue;
//每三位一输出
if ((i + 1) % 3 == len % 3 && i != len - 1)
cout << ",";
}
return 0;
}