1378 - 字符串连接

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

题目输入

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

题目输出

可能有多组测试数据,对于每组数据,

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

输入/输出样例

题目输入

abc def

题目输出

abcdef

C语言解答

#include <stdio.h>   
#include <stdlib.h>   
  
void contact(char *str, const char *str1, const char *str2);  
  
int main()  
{  
    char str[201], str1[101], str2[101];  
  
    while(scanf("%s%s",str1,str2) != EOF)  
    {  
        contact(str, str1, str2);  
        printf("%s\n",str);  
    }  
    return 0;  
}  
void contact(char *str, const char *str1, const char *str2)  
{  
    int i, j;  
      
    for(i = 0; str1[i] != '\0'; i ++)  
    {  
        str[i] = str1[i];  
    }  
    for(j = 0; str2[j] != '\0'; j ++)  
    {  
        str[i + j] = str2[j];  
    }  
    str[i + j] = '\0';  
}

C++解答

#include <stdio.h>
#include <string.h>

int main(){
	char str1[220], str2[110];
	while(scanf("%s%s", str1, str2) != EOF){
		puts(strcat(str1, str2));
	}

	return 0;
}

时间限制 1 秒
内存限制 32 MB
讨论 统计
上一题 下一题