题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <stdio.h>
#include <string.h>
int main() {
char input[100],output[9],ch;
int len=0,i=0,j=0;
//读取输入字符串
scanf("%s",input);
output[8]='\0';
//获取字符串长度
len=(strlen(input)%8==0)?strlen(input)/8:strlen(input)/8+1;
//拆分字符串
while(i<len){
strncpy(output, input+8*i,8);
if((strlen(input)%8!=0)&&i+1==len){
//当input的字符小于8的时候
for(j=strlen(input)%8;j<8;j++){
output[j]='0';
}
}
printf("%s\n",output);
i++;
}
return 0;
}
#华为笔试#

