PAT:1001. A+B Format (20) AC
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
int sum=a+b;
if(sum<0)
{
printf("-");
sum=-sum;
}
if(sum>=1000000) //【思维】,两个数字在:-1000000 <= a, b <= 1000000,之和不会超过1000000再加三个0的数量级
printf("%d,%03d,%03d",sum/1000000,sum%1000000/1000,sum%1000);
else if(sum>=1000)
printf("%d,%03d",sum/1000,sum%1000);
else
printf("%d",sum);
return 0;
}