#include <iostream>
#include <vector>
using namespace std
;
int main(){
int a
,b
;
cin
>>a
>>b
;
vector
<char> v
;
int j
=0;
string s
=to_string(a
+b
);
int len
=s
.length();
for(int i
=len
-1;i
>=0;i
--){
v
.push_back(s
[i
]);
j
++;
if(j
%3==0&&s
[i
-1]!='-'&&i
!=0) v
.push_back(',');
}
for(int k
=v
.size()-1;k
>=0;k
--)
cout
<<v
[k
];
return 0;
}
liuchuo的方法非常巧妙,但是不太容易想到
#include <iostream>
using namespace std
;
int main(){
int a
,b
,c
;
cin
>>a
>>b
;
string s
= to_string(a
+b
);
int len
= s
.length();
for(int i
=0;i
<len
;i
++){
cout
<<s
[i
];
if(s
[i
]=='-') continue;
if((i
+1)%3==len
%3&&i
!=len
-1) cout
<<",";
}
return 0;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-65497.html