题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <stdio.h> #include <stdlib.h> #include <string.h> void divide(char* str, int length) { char* curr = str; char str1[1000] = { 0 }; int a = length / 8; //按长度为8拆分每个输入字符串 int b = length % 8; for (int i = 0; i < a; i++) { for (int j = 0; j < 8; j++) { printf("%c", *curr++); } printf("\n"); } for (int k = 0; k < b && *curr != '/0'; k++) { printf("%c", *curr++); } if (b > 0) { for (int m = 0; m < 8 - b; m++) { printf("0"); } } } int main() { char str[1000] = { 0 }; gets(str); int length = strlen(str); divide(str, length); return 0; }