1001. A+B Format (20)
2018-01-25 13:09
211 查看
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
Sample Output
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
#include <stdio.h> int main() { int n, m, count; scanf("%d%d", &n, &m); count = n + m; if(count < 0) { printf("-"); count = -count; } if(count >= 1000000) { printf("%d,%03d,%03d", count/1000000, (count%1000000)/1000, count%1000); } else if(count >= 1000) { printf("%d,%03d", count/1000, count%1000); } else { printf("%d", count); } return 0; }
相关文章推荐
- PAT A1001 A+B Format(20)
- Java - PAT - 1001. A+B Format (20)
- PAT 1001 A+B Format (20)
- pat 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001 A+B Format (20)
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- 1001. A+B Format (20)
- PAT 1001. A+B Format (20)
- 【PAT】1001. A+B Format (20)
- 1001.A+B Format (20)(思路,bug发现及其修改,提交记录)
- 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001 A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- PAT A 1001. A+B Format (20)
- PAT甲题题解-1001. A+B Format (20)-字符串处理,水
- 1001. A+B Format (20)