游客 Signup | Login
中文 | En

1195 - C语言7.19

读入两个字符串,并将其连接起来的新字符串输出。要求不要使用strcat函数。

Input

两行不包含空格的字符串。保证每个字符串的长度不超过100。

Output

将第2行的字符串连接在第1行字符串之后的新字符串。

请注意行尾输出换行。

Examples

Input

I am a program.
This is a program.

Output

I am a program.This is a program.

Solution C

#include<stdio.h>
#include<string.h>
int main()
{
	char a[202],b[102];
	int i,k,l1,l2;
	gets(a);
	gets(b);
	l1=strlen(a);
	l2=strlen(b);
	for(k=0,i=l1;i<(l1+l2)&&k<l2;i++)
		a[i]=b[k++];
	a[l1+l2]='\0';
	puts(a);
	return 0;
}

Solution C++

#include <stdio.h>
#include <string.h>
int main() {
	char str[2][101], newstr[201];
	int i, j, length = 0;
	for (i = 0;i < 2;i++)
		gets(str[i]);
	for (i = 0;i < 2;i++) {
		for (j = 0;str[i][j] != '\0';j++) {
			newstr[length++] = str[i][j];
		}
	}
	newstr[length] = '\0';
	puts(newstr);
	return 0;
}

Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题