PAT A1001. A+B Format
2015-03-06 23:30
169 查看
1001. A+B Format (20)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
#include <stdio.h>
int main() {
int a, b, sum, m, n, p;
scanf("%d%d", &a, &b);
sum = a + b;
if(sum < 0) {
printf("-");
sum = sum * (-1);
}
m = sum / 1000000;
n = sum % 1000000 / 1000;
p = sum % 1000;
if(m == 0) {
if(n == 0) {
printf("%d", p);
} else {
printf("%d,%03d", n, p);
}
} else {
printf("%d,%03d,%03d", m, n, p);
}
return 0;
}
相关文章推荐
- PAT A 1001. A+B Format (20)
- PAT A 1001. A+B Format (20)
- PAT A1001. A+B Format
- PAT A1001 A+B Format(20)
- PAT A 1001 A+B Format
- 1001. A+B Format (20)
- 1001. A+B Format
- 1001. A+B Format (20)
- PAT-A 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 1001. A+B Format
- 1001. A+B Format (20)
- PAT甲级.1001. A+B Format (20)
- pat甲级1001. A+B Format (20)
- 1001. A+B Format (20) C++
- 1001. A+B Format解析