题解 | 字符串分隔
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7?tpId=37&tqId=21227&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
#include <stdio.h>
#include <string.h>
int main()
{
int i,j,k,l;
char str[101];
char a,b;
scanf("%s",str);
i=strlen(str);
if(i<8)
{
printf("%s",str);
for (j=0;j<8-i;j++) {
printf("0");
}
}
else
if(i==8)
{
printf("%s",str);
}
else{
b=i%8;
for (j=0;j<i;j++) {
if(j>=8&&j%8==0)
printf("\n");
printf("%c",str[j]);
}
l=8-b;
if(l<8)
for (j=0;j<l;j++) {
printf("0");
}
}
}
本题考察的是字符串,先将输入的字符串按长度进行分类然后分别处理,利用判断语句来实现每行输出8个字符,满8个字符之后输出换行符,当输入的字符串多于8位且不能被8整除,在最后一行输出后面补上几个0,使其满足8位。
#牛客创作赏金赛##字符串算法#

查看14道真题和解析