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
思路:题目意思是两数相加后的结果每三位加一个逗号,我的做法是把取余的每位都保存在字符栈中,每取三位加一个逗号,最后出栈即可,区分下正数负数和零的情况即可。
Code:
1 | using namespace std; |