AcWing 1473. A + B 格式
原题链接
简单
作者:
Value
,
2020-05-22 12:12:02
,
所有人可见
,
阅读 633
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
int sum = a + b;
vector<int> res;
if(sum < 0){
cout << "-";
sum = -sum;
}
// 特判
if(sum == 0){
cout << sum << endl;
return 0;
}
while(sum){
res.push_back(sum % 10);
sum /= 10;
}
string s = "";
for(int i = 0, k = 1; i < res.size(); i ++, k ++ ){
s += (res[i] + '0');
if(k == 3 && i != res.size() - 1){
s += ',';
k = 0;
}
}
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
}