题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[100];
int len;
int i;
int j = 0;
int k = 0;
char b[9];
scanf("%[^\n]", &a);
len = strlen(a);
while (len >= 8)
{
for (i = 0; i < 8; i++)
{
b[i] = a[j];
j++;
}
b[j] = '\0';
len = len - 8;
printf("%s\n", b);
i = 0;
}
if(len<8&&len>=1)
{
for(i=0;i<len;i++)
{
b[i]=a[j];
j++;
}
for(k=0;k<(8-len);k++)
{
b[len+k]='0';
}
b[len + k ] = '\0';
printf("%s\n",b);
}
return 0;
}
#include<string.h>
int main(void)
{
char a[100];
int len;
int i;
int j = 0;
int k = 0;
char b[9];
scanf("%[^\n]", &a);
len = strlen(a);
while (len >= 8)
{
for (i = 0; i < 8; i++)
{
b[i] = a[j];
j++;
}
b[j] = '\0';
len = len - 8;
printf("%s\n", b);
i = 0;
}
if(len<8&&len>=1)
{
for(i=0;i<len;i++)
{
b[i]=a[j];
j++;
}
for(k=0;k<(8-len);k++)
{
b[len+k]='0';
}
b[len + k ] = '\0';
printf("%s\n",b);
}
return 0;
}