题目信息
题目
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
1 | -1000000 9 |
Sample Output
1 | -999,991 |
题目来源
解题思路
思路分析
此题是个很常规的A+B的题,将两个数相加,正常输出,并注意每三个数之间一个逗号分隔
题目的数据只有-1000000 - 1000000,用自带的int类型足够存储了,也就不需要利用字符串的思想来计算了,因此直接对两个int数相加即可
数据输出,我采用的是栈的思想,将数据的每一位求出来,依次压栈,并据情况压入逗号
注意事项
注意结果为0时,要输出为0
结果为三位数时,无逗号
算法实现
1 |
|
结果
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 6 | 384 | 9/9 |
1 | 答案正确 | 12 | 384 | 1/1 |
10 | 答案正确 | 12 | 384 | 1/1 |
11 | 答案正确 | 12 | 384 | 1/1 |
2 | 答案正确 | 6 | 380 | 1/1 |
3 | 答案正确 | 3 | 384 | 1/1 |
4 | 答案正确 | 12 | 384 | 1/1 |
5 | 答案正确 | 9 | 384 | 1/1 |
6 | 答案正确 | 7 | 384 | 1/1 |
7 | 答案正确 | 11 | 384 | 1/1 |
8 | 答案正确 | 13 | 384 | 1/1 |
9 | 答案正确 | 40 | 376 | 1/1 |