#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a,b;
cin>>a>>b;
int c=a+b;
int f=0;//如果说相加为附属就需要注意负号的问题了
if(c<0)f=1;
c=abs(c);
string s;
int k=1;
if(c==0)s+='0';//考虑答案是0那么就无法进行下面操作
while(c)
{
if(k%3==1&&k!=1)s+=',';//每三次加逗号
s+=c%10+'0';
c/=10;
k++;
}
if(f)s+='-';
reverse(s.begin(),s.end());//反转字符串
cout<<s;
return 0;
}
PAT甲级题库1001 A+B Format
于 2023-02-07 22:16:28 首次发布