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"
#include "stdlib.h"
int main(){
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){
int i=0,t[10]={0};
int c=a+b;
//printf("%d",c);
int y=c;
//计算有几个3位
while(y){
t[i]=y%1000;
y=y/1000;
i++;
//printf("%d\n",t[i-1]);
}
//0的情况
if(i==0){printf("0\n");}
else{
//输出高位的数
printf("%d",t[i-1]);
for(int j=i-2;j>=0;j--){
//判断后面的位数是否满足3位,否则视情况填0
int k=0,m=t[j];
while(m){
k++;
m=m/10;
}
switch(k){
case 0:printf(",000");break;
case 1:printf(",00%d",abs(t[j]));break;
case 2:printf(",0%d",abs(t[j]));break;
case 3:printf(",%d",abs(t[j]));break;
}
}
printf("\n");
}//else
}//while
}