题目
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 −106≤a,b≤106. 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:
|
|
Sample Output:
|
|
分析
使用递归按照1000不断分离数位,先打印高位,然后补逗号继续打印后三位。 要注意的地方:中间要打印的数可能不满三位,需要在左边用0补足,printf("%0md");m为总共要输出的位数,0表示前面补0。还有就是区间的问题,开始一个>1000,一个<1000忘了考虑1000的情况直接没输出。第一次做PAT有点儿郁闷。
代码
|
|