1001 A+B Format (20 point(s))

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a,b, sum = 0;
cin>>a>>b;
sum = a+b;
string s = to_string(sum);
if (s.size()<4){
cout<<sum;
}else {
string res = "";
int count = 0;
for (int i = s.size() - 1; i > 0; --i) {
res += s[i];
count++;
if (count == 3) {
if (s[i-1] != '-' || (s[i-1]>='0')) res += ',';
count = 0;
}
}
res += s[0];
std::reverse(res.begin(), res.end());
cout << res;
}
return 0;
}

1001 A+B Format (20 point(s))
https://pisces34.github.io/2021/09/07/patA/1001/
发布于
2021年9月7日
许可协议