版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiang_6/article/details/90200649
字符串操作
#include<bits/stdc++.h>
#define FI first
#define SE second
using namespace std;
const int maxn = 1000 + 7;
typedef long long ll;
typedef pair<int,int> P;
int a, b;
int main() {
cin >> a >> b;
a += b;
if(a < 0) {
cout << '-';
a *= (-1);
}
int t = 0;
string s;
while(1) {
s.push_back((char)(a%10+'0'));
a /= 10;
t++;
if(!a) break;
if(t == 3) {
s.push_back(',');
t = 0;
}
}
reverse(s.begin(), s.end());
cout << s;
return 0;
}