Calculate 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 pair of integers a and where . The numbers are separated by a space.
Output Specification:
For each test case, you should output the sum of and in one line. The sum must be written in the standard format.
Sample Input:
-1000000 9
Sample Output:
-999,991
using namespace std;
int main(){
int a, b;
cin >> a >> b;
int c = a + b;
string s = to_string(c);
string res;
for(int i = s.size() - 1, j = 0; i >= 0; i--){
res = s[i] + res;
j++;
if(j % 3 == 0 && i && s[i - 1] != '-'){
res = ',' + res;
j = 0;
}
}
cout << res << endl;
return 0;
}