ZCMU 4921

4921: 字符串连接

Description

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

Input

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

Output

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

Sample Input

abc def

Sample Output

abcdef

网上大佬的代码 嘿嘿嘿 简单易懂
Code:

#include <stdio.h>
#include <stdlib.h>
void contact(char *s, char *s1, char *s2)
{
    int i, j;
    for(i = 0; s1[i] != '\0'; i ++)
    {
        s[i] = s1[i];
    }
    for(j = 0; s2[j] != '\0'; j ++)
    {
        s[i + j] = s2[j];
    }
    s[i + j] ='\0';
}

int main()
{
    char s[201];
    char s1[101];
    char s2[101];

    while(scanf("%s %s",s1,s2) != EOF)
    {
        contact(s, s1, s2);
        printf("%s\n",s);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44941429/article/details/91519834