题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include <stdio.h>
int main()
{
long n = 0;
scanf("%ld", &n);
long m = n;
int arr[20] = { 11 };
int count = 0;
while (m)
{
int a = m % 10;
arr[count] = a;
m = m / 10;
count++;
}
int count1 = 0;
for (int i = count-1; i >= 0; i--)
{
if(count>3)
{
if (count%3==0&&count1 % 3==0&&count1!=0)
printf(",");
else if(count%3==1&&(count1==1||(count1-1)%3==0))
printf(",");
else if(count%3==2&&(count1==2||(count1-2)%3==0))
printf(",");
else
;
}
printf("%d", arr[i]);
count1++;
}
return 0;
}
查看25道真题和解析