题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7?tpId=37&tqId=21227&rp=1&ru=/exam/company&qru=/exam/company&sourceUrl=%2Fexam%2Fcompany%3FjumpFrom%3D%25E6%259C%25AA%25E7%2599%25BB%25E5%25BD%2595%25E9%25A6%2596%25E9%25A1%25B5&difficulty=undefined&judgeStatus=undefined&tags=&title=
#include <stdio.h>
#include<string.h>
#include<malloc.h>
int main() {
char s[100];
gets(s);
int n = strlen(s);
int t = n / 8;
if (n % 8 != 0)
t++;
char** ns = malloc(sizeof(char*) * t);
for (int i = 0; i < t; i++)
{
ns[i] = malloc(sizeof(char)*8);
}
int j = 0, p = 0;
for (int i = 0; i < n; i++)
{
if (p == 8)
{
j++;
p = 0;
}
ns[j][p++] = s[i];
}
if (p < 8)
for (int i = p; i < 8; i++)
{
ns[j][i] = '0';
}
for (int i = 0; i < t; i++)
printf("%s\n", ns[i]);
return 0;
}
