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 9Sample Output
-999,991
计算a和b的和,然后标准化输出
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int sum=a+b;
char s[100];
int cnt=0,fz=1;
if(sum<0) fz=0,sum*=-1;
while(sum){
s[cnt++]=sum%10+'0';
sum/=10;
}
if(cnt==0){
cout<<0;
return 0;
}
if(!fz) cout<<'-';
for(int i=cnt-1;i>=0;i--) {
if((i+1)%3==0&&i!=cnt-1) cout<<','<<s[i]-'0';
else cout<<s[i]-'0';
}
return 0;
}