解释一下if,先执行前置的--n,因为是三位一加,所以逗号出现在7,4等位后,先减再判断是否为三的倍数,&&n判断是不是最后一位
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;cin>>s;
int n=s.size();
for(int i=0;i<s.size();++i){
cout<<s[i];
if(--n%3==0&&n)cout<<',';
}
}
// 64 位输出请用 printf("%lld")



京公网安备 11010502036488号