题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string str; cin >> str; reverse(str.begin(),str.end()); string retstr; size_t len = str.size(); for(int i = 1;i <= len ;i++) { retstr += str[i-1]; if(i%3 == 0 && i != len) retstr += ','; } reverse(retstr.begin(),retstr.end()); cout << retstr << endl; return 0; }