字符串分隔,C满分答案

字符串分隔

http://www.nowcoder.com/questionTerminal/d9162298cb5a437aad722fccccaae8a7

#include <stdio.h>
#include <stdlib.h>
#define str_lenth 100
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int func_lenth(char* str,int lenth)                                //测量字符串长度函数 
{
    int i;

    for(i=0;i<lenth;i++)                                        
    {    
        if(str[i]=='\0')
        {
            lenth=i;
            break;
        }
    }

return lenth;
}

int main() 
{
char a[str_lenth]={0};
char b[str_lenth]={0};    
int i,j;
int head=1,rear=0;
int l_a,l_b;    


scanf("%s",a);
scanf("%s",b);

l_a=func_lenth(a,str_lenth);
l_b=func_lenth(b,str_lenth);


for(i=0;i<l_a;i++)                                                //满8的字符输出,不满的输出前面字符 
{
if((i+1)%8==0)printf("%c\n",a[i]);
else     printf("%c",a[i]);    
}
if(i%8!=0)                                                  //不满8的字符后补上字符0 
{
    while((i+1)%8)
    {
    printf("%c",'0');
    i++;
    }
    printf("%c\n",'0');
}

for(i=0;i<l_b;i++)                                                //处理第二个字符串 
{
if((i+1)%8==0)printf("%c\n",b[i]);
else     printf("%c",b[i]);    
}

if(i%8!=0)
{
    while((i+1)%8)
    {
    printf("%c",'0');
    i++;
    }
    printf("%c\n",'0');
}

//while(1);
}
全部评论
代码只能处理两个字符串的输入,题目为连续输入字符串
1 回复
分享
发布于 2021-04-16 18:08

相关推荐

点赞 评论 收藏
转发
3 收藏 评论
分享
牛客网
牛客企业服务