1.主要是字符串处理,然后插入逗号
2.注意正负数
3.输入可以直接使用int类型读取
AC代码
//#include<string>
//#include<stack>
//#include<unordered_set>
//#include <sstream>
//#include "func.h"
//#include <list>
#include <iomanip>
#include<unordered_map>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include <algorithm>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
#include<stack>
using namespace std;
int main(void)
{
int a, b;
cin >> a >> b;
int result = a + b;
bool sign = true;//正负符号标志位
if (result < 0)
{
result = -result;
sign = false;
}
string str = "";
if (result == 0) str = "0";
while (result != 0)
{//转化成string
char c = result % 10 + '0';
str += c;
result /= 10;
}
//此时的str是倒序的
string output = "";
for (int i = 0; i < str.size() - 1; i++)
{
output = str[i] + output;
if ((i+1) % 3 == 0)
output = ',' + output;
}
output = str[str.size() - 1] + output;
if (!sign) output = "-" + output;
cout << output << endl;
return 0;
}