题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include <stdio.h> #include <string.h> #define N 15 char a[N]; char b[N * 2]; int main() { scanf("%s", a); int k = 0; for (int i = strlen(a) - 1, j = 1; i >= 0; i -- , j ++ ) { b[k ++ ] = a[i]; if (j == 3 && i) { b[k ++ ] = ','; j = 0; } } for (int i = strlen(b) - 1; i >= 0; i -- ) printf("%c", b[i]); return 0; }