AcWing 1473. A + B 格式
原题链接
简单
作者:
pingsheng
,
2021-01-03 20:35:36
,
所有人可见
,
阅读 451
#include <iostream>
#include <string>
using namespace std;
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
long a, b, c;
cin >> a >> b;
c = a + b;
long d = abs(c);
string num;
while (d)
{
num = char((d % 10)+'0') + num;
d /= 10;
}
string res;
for (int i = num.size() - 1, j = 0; i >= 0; i--)
{
res = num[i] + res;
++j;
if (j % 3 == 0 && i && num[i - 1] != '-')
res = ',' + res;
}
cout << res << endl;
return 0;
}