1001 A+B Format
Calculate 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 and where . The numbers are separated by a space.
Output Specification:
For each test case, you should output the sum of and in one line. The sum must be written in the standard format.
Sample Input:
1 | -1000000 9 |
Sample Output:
1 | -999,991 |
思路
- 使用Python处理字符串,一下子就简单了很多,当然这题用C++的
string
类拼接也可以,并不麻烦。不过我还是建议使用Python,因为所以的点都能过。 - 读取两个数,求它们的和,保存成字符串。
- 然后从后向前遍历,每隔三个位置,加一个逗号。
- 当再向前一个是负号的时候不用加逗号了。
代码
1 | a = str(sum(list(map(int,input().split())))) |
太水了这题。