a+b和按要求输出
1. 原文
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 −
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:
1 | -1000000 9 |
Sample output:
1 | -999,991 |
2. 解析
a,b两数相加的和按格式输出
求和结果的位数
1 | do{ |
求得的数组是从个位到最高位排列的199999
从个位开始,cnt=1,循环遍历,每次cnt++表示前进一位,当遍历满三位时ans+=’,’ —>199,
⚠️注意处理最后一位,9前面不加 199,999
最后字符串反向输出 999,991
3. AC代码
1 |
|
Gitalking ...