题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <stdio.h>
int main(void)
{
char str[108];
char ch;
int count=0,res=0;
while((ch = getchar())!= '\n')
{
str[count++] = ch;
}
if(str[0]=='\n')
{
printf("%s\n",str);
return 0;
}
res = count % 8;
if((res) != 0)
{
for(int i=0;i<8-res;i++)
{
str[count+i] = '0';
}
for(int i=0;i<count+8-res;i++)
{
printf("%c",str[i]);
if(((i+1)%8 == 0) && i != count+8-res-1)
{
printf("\n");
}
}
}
else{
for(int i=0;i<count;i++)
{
printf("%c",str[i]);
if(((i+1)%8 == 0))
{
printf("\n");
}
}
}
return 0;
}
科大讯飞公司氛围 472人发布