题解 | 添加逗号
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
reverse(s.begin(),s.end()); //先反转,从低位开始
string s1;
int i,count=0;
for(char c:s)
{
count++;
i++;
s1+=c;
if(count==3&&i!=s.size()) //每3位一添加
{
count=0;
s1+=",";
}
}
reverse(s1.begin(),s1.end()); //反转输出
cout<<s1<<endl;
return 0;
}
// 64 位输出请用 printf("%lld")
文远知行公司福利 593人发布
