Codeup-问题 A: 字符串连接

题目描述

不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

输入

每一行包括两个字符串,长度不超过100。

输出

可能有多组测试数据,对于每组数据,
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输出连接后的字符串。

样例输入

abc def

样例输出

abcdef

这一题唯一要注意的一点就是,在将两个字符串连接起来之后,最后一位(末尾)添加一个'\0',否则不能通过编译

具体代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main()
{
    char a[210]={},b[105]={};
    while(scanf("%s%s",a,b)!=EOF)
    {
        int len1=strlen(a);
        int len2=strlen(b);
        int i,j;
        for(i=len1,j=0;j<len2;i++,j++)
            a[i]=b[j];
        a[i]='\0';
        printf("%s\n",a);

    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Zizizi9898/article/details/88885471