题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
char str[100];
while(scanf("%s",str) != EOF){
int str_num = strlen(str);
if(str_num == 0) continue;
div_t a = div(str_num,8);
for(int i = str_num; i < (str_num + 8 - a.rem);i++){
str[i] = '0'; //补位,注意在位数为8的整数倍时会补8位
} //(a.rem > 0) 规避输出位数为8的整数倍时多补的8位0
for(int i = 0;i< a.quot + (a.rem > 0);i++){
printf("%c%c%c%c%c%c%c%c\n",str[i*8+0],str[i*8+1],str[i*8+2],str[i*8+3],str[i*8+4],str[i*8+5],str[i*8+6],str[i*8+7]);
}
}
return 0;
}
无
无