#include <stdio.h>
int main()
{
int a,b,sum,num[100000] = {11},len = 0,summ,Sum;
scanf("%d %d",&a,&b);
sum = a+b;
summ = sum;
if(sum<0)
sum = -sum;
Sum = sum;
if(sum==0)
printf("0");
for(int i=0;sum!=0;i++){
num[i] = sum%10;
sum /= 10;
len++;
}
int cnt = 0,k=0;
for(int j=len-1;j>=0;j--){
if(summ<0&&j==len-1)
printf("-");
printf("%d",num[j]);
k++;
int a = len%3;
if(k>len%3){
cnt++;
if(cnt%3==0&&j!=0){
printf(",");
cnt = 0;
}
}
if(k==len%3&&Sum>999)
printf(",");
}
return 0;
}
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 Specification:
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.
Output Specification:
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