首页 > 试题广场 >

字符串链接

[编程题]字符串链接
  • 热度指数:8791 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
不用strcat 函数,自己编写一个字符串链接函数MyStrcat(char dstStr[],charsrcStr[])

输入描述:
两个字符串,字符串由小写字母组成。


输出描述:
链接后的字符串
示例1

输入

hello world
good morning

输出

helloworld
goodmorning

	
#include<stdio.h> #include<string.h>//  void Mystrcat(char first[], char last[]){ int i = 0; int j = 0; while (first[i] != '\0') { i++;
    } while (last[j] != '\0') { first[i] = last[j]; i++; j++;
    } first[i] = '\0'; printf("%s",first); printf("\n"); for (int i = 0;i<100;i++) {
        first[i] = '\0';
        last[i] = '\0';
    }
} int main(int argc, char *argv[]) { char first1[100]; char last1[100]; for (int i = 0;i<2;i++) {
        scanf("%s %s",first1,last1);
        Mystrcat(first1,last1);
    }
}
发表于 2026-03-07 22:22:31 回复(0)
#include<stdio.h>
#include<string.h>

void MyStract(char a[],char b[])
{
	int len=strlen(a);
	for(int i=0;i<strlen(b);i++)
		a[len++]=b[i];
	a[len]='\0';
}

int main()
{
	char a[100];
	char b[100];
	while(scanf("%s%s",a,b)!=EOF)
	{
		MyStract(a,b);
		printf("%s\n",a);
	}
	return 0;
}

发表于 2022-03-22 16:34:51 回复(0)