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).
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.
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.
-1000000 9
-999,991
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include
#include
int main()
{
int a=0,b=0,sum=0;
scanf("%d %d",&a,&b);
sum=a+b;
if(sum/1000000)
{
printf("%d",sum/1000000);
printf(",");
printf("%03d",abs(sum%1000000/1000));
printf(",");
printf("%03d",abs(sum%1000000%1000));
}
if(sum/1000000==0&&sum/1000)
{
printf("%d",sum/1000);
printf(",");
printf("%03d",abs(sum%1000));
}
if(sum/1000000==0&&sum/1000==0)
printf("%d",sum);
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章