题解 | #添加逗号#

添加逗号

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;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务