题解 | #字符串分隔#

字符串分隔

https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

#include<stdio.h>
#include<string.h>

int main()
{
	char str[100] = { 0 };
	int n = 0;
	int a = 0;
	int count = 0;

	while (scanf("%s", str) != EOF)
	{
		n = strlen(str);
		if (n % 8 != 0)
		{
			a = n % 8;
			for (int i = n; i < n + (8 - a); i++)
			{
				str[i] = '0';
			}
		}
		for (int j = 0; j < (strlen(str)); j++)
		{
			count++;
			printf("%c", str[j]);
			if (count % 8 == 0)
			{
				printf("\n");
			}
		}


	}


	return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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