#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
freopen("D://input.txt", "r", stdin);
int a, b;
int ret, lgt, cut;
cin >> a >> b;
ret = a + b;
string output, temp;
if (ret < 0)
output = "-";
ret = fabs(ret);
temp = to_string(ret);
if (ret < 1000)
output += temp;
else if (ret >= 1000 && ret < 1000000) {
lgt = temp.length();
cut = lgt - 3;
output += temp.substr(0, cut) + "," + temp.substr(cut, 3);
}
else {
lgt=temp.length();
cut = lgt - 6;
output += temp.substr(0, cut) + "," + temp.substr(cut, 3) + "," + temp.substr(cut + 3, 3);
}
cout << output << endl;
return 0;
}1001. A+B Format (20)
最新推荐文章于 2021-03-31 11:42:31 发布
本文介绍了一个使用C++进行数值格式化输出的例子程序。该程序读取输入文件中的两个整数,计算它们的和,并根据数值大小将其格式化为带有千位分隔符的标准形式。文中展示了如何处理负数及不同数量级的数值格式化。
1567

被折叠的 条评论
为什么被折叠?



