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