1001. A+B Format (20) (%0nd)

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

解题思路:这里主要是注意一下补0的问题

     %nd:n代表的是列宽长度。

(1)%-nd   -  代表的是左对齐。

(2)%nd       代表的是右对齐。

(3)%0nd   0(数字零)代表的是不足n位长度的左补齐0。

 #include<stdio.h>
#include<stdlib.h> int main()
{
int a,b;
int sum = ;
scanf("%d %d",&a,&b); sum = a+b;
if( sum<){
printf("-");
sum = -sum;
}
if( sum>=){
printf("%d,%03d,%03d",(sum/),(sum/%),(sum%));
}
else if( sum>=){
printf("%d,%03d",(sum/),(sum%));
}
else printf("%d",sum);
return ;
}
上一篇:PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏


下一篇:BZOJ 3129 [SDOI2013]方程 (拓展Lucas)