#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
//输入
int x1,x2;
cin>>x1>>x2;
int sum = x1+x2;
//转换成字符串或者输入到数组中比较方便
string s = to_string(sum);
//首先将'-'处理掉
if(s[0]=='-'){
cout<<"-";
s.erase(0,1);
}
//将结果保存到res中
int count=0;
string res="";
for(int i=s.size()-1;i>=0;i--){
res+=s[i];
count++;
if(count % 3 == 0 && i!=0) res+=',';
}
reverse(res.begin(),res.end());
cout<<res;
}
PAT甲级1001 A+B Format
最新推荐文章于 2024-07-25 21:13:04 发布