版权声明:copyright©CodeIover reserved https://blog.csdn.net/qq_40073459/article/details/86553898
问题 A: 字符串连接
题目描述
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输入
每一行包括两个字符串,长度不超过100。
输出
可能有多组测试数据,对于每组数据,
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输出连接后的字符串。
样例输入
abc def
样例输出
abcdef
实现代码:
#include<stdio.h>
int strlen(char str[])
{
int i;
for(i=0;str[i]!='\0';i++);
return i;
}
int main()
{
char str1[101],str2[101];
while(scanf("%s %s",str1,str2)!=EOF)
{
int len1=strlen(str1);
int len2=strlen(str2);
int len=len1+len2;
char res[len];
int i;
for(i=0;i<len1;i++)
{
res[i]=str1[i];
}
for(int j=0;i<len;i++,j++)
{
res[i]=str2[j];
}
res[len]='\0';
printf("%s\n",res);
}
return 0;
}