The meaning of problems
Given a, b, and a + b is obtained, then every three numbers separated by commas, unless fewer than three.
Thinking
To_string use to convert the data string, and then every three reverse comma
Code
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
string s=to_string(a+b);//将数据转换为字符串
for(int i=(int)s.length()-1;i>=0;i--){//从右往左加逗号
cout<<s[s.length()-1-i];
if(s[s.length()-1-i]=='-') continue;//-号后不加逗号
if(i%3==0&&i) cout<<',';
}
return 0;
}