题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
long long a = 0;
scanf("%lld",&a);
int tmp = a;
char arr[100] = { 0 };
int count = 0;
while (tmp)
{
count++;
tmp = tmp / 10;
}
int count1 = count;
int i = 0;
int j = 1;
for ( i = 0; count ; i++)
{
arr[i] = a % 10+48;
if ((j) % 3 == 0&&a>10)
{
arr[i + 1] = ',';
i++;
count1++;
}
j++;
count--;
a = a / 10;
}
arr[i] = '\0';
for (int j = count1-1; j>=0; j--)
{
printf("%c", arr[j]);
}
return 0;
}
查看10道真题和解析