题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include<stdio.h> #include<string.h> int main() { char a[20]; scanf("%s",a); int len=strlen(a),count=0; char *p=a; for( ;p<(a+len);p++) { if(len%3==0) { if((count)%3==0&&count!=0) printf(","); count++; printf("%c",*p); } else { int c=len%3; if((count-c)%3==0) printf(","); count++; printf("%c",*p); } } return 0; }