首页 > 试题广场 >

字符串连接

[编程题]字符串连接
  • 热度指数:15669 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

输入描述:
每一行包括两个字符串,长度不超过100。


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

输入

abc def

输出

abcdef
#include <stdio.h>

int main() {
    int c;
    c=getchar();
    while (c!=EOF) {
        if (c!=' ') {
            putchar(c);
        }
        c=getchar();
    }
    return 0;
}

发表于 2024-01-31 10:48:24 回复(0)
#include <stdio.h>

int main() {
    char str1[200],str2[100];
    while(scanf("%s %s",str1,str2) != EOF){
        int i = 0;
        while(str1[i++] != '\0');
        int j = 0;
        i--;
        while(str2[j] != '\0'){
            str1[i++] = str2[j++];
        }
        str1[i] = '\0';
        printf("%s",str1);
    }

    return 0;
}

发表于 2023-02-13 17:23:16 回复(0)
///KY208 字符串连接
///不使用字符串库函数就是说用char
///无冗余那就不能用数组
///可以用%c一个一个输入然后判断
///字符串是指针,读的是地址,故%s输入时不用加&

int main()
{
    char x;
    int i;
    while(scanf("%c",&x)!=EOF)
    {
        printf("%c",x);
        while(1)
        {
            scanf("%c",&x);
            if(x==' ')
                continue;
            else if(x>='0'&&x<='z')///包括数字和字母
                printf("%c",x);
            else
                break;
        }
    }
}
发表于 2023-01-22 23:18:30 回复(0)

问题信息

难度:
3条回答 10825浏览

热门推荐

通过挑战的用户

查看代码