串结构练习——字符串连接
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
给定两个字符串string1和string2,将字符串string2连接在string1的后面,并将连接后的字符串输出。
连接后字符串长度不超过110。
输入
输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2。
输出
对于每组输入数据,对应输出连接后的字符串,每组输出占一行。
示例输入
123 654 abs sfg
示例输出
123654 abssfg
提示
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
char concat(char T[],char s1[],char s[]) //s1 s连接成为新串T,s1在前
{
int n=strlen(s1), m=strlen(s);
T=new char[n+m+1];
int j=0,k=0;
while(s1[j]!='\0')
T[k++]=s1[j++];
j=0;
while(s[j]!='\0')
T[k++]=s[j++];
T[k]=='\0';
int i;
for(i=0;i<k;i++)
cout<<T[i];
cout<<endl;
}
{
int n=strlen(s1), m=strlen(s);
T=new char[n+m+1];
int j=0,k=0;
while(s1[j]!='\0')
T[k++]=s1[j++];
j=0;
while(s[j]!='\0')
T[k++]=s[j++];
T[k]=='\0';
int i;
for(i=0;i<k;i++)
cout<<T[i];
cout<<endl;
}
int main()
{
char a[10000],b[110000],c[1000000];
{
char a[10000],b[110000],c[1000000];
while(cin>>a>>b)
concat(c,a,b);
int l=strlen(c);
int i;
for(i=0;i<l;i++)
cout<<c[i];
cout<<endl;
}
concat(c,a,b);
int l=strlen(c);
int i;
for(i=0;i<l;i++)
cout<<c[i];
cout<<endl;
}