串结构练习——字符串连接

串结构练习——字符串连接
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic Discuss
Problem Description

给定两个字符串string1和string2,将字符串string2连接在string1的后面,并将连接后的字符串输出。
连接后字符串长度不超过110。
Input

输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2。

Output

对于每组输入数据,对应输出连接后的字符串,每组输出占一行。

Sample Input

123
654
abs
sfg
Sample Output

123654
abssfg
Hint

Source

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char s1[112],s2[112],s3[112];
void combine(char s1[112],char s2[112],char s3[112])
{
    int i=0,cn=0;
    while(s1[i]!='\0')
    {
        s3[cn++]=s1[i++];
    }
    i=0;
    while(s2[i]!='\0')
    {
        s3[cn++]=s2[i++];
    }
}
int main()
{
    while(~scanf("%s",s1))
    {
        scanf("%s",s2);
        memset(s3,0,sizeof(s3));
        combine(s1,s2,s3);
        puts(s3);
    }
    return 0;
}

建立三个数组,一个数组是合并用的,另外两个是输入数据的时候用

猜你喜欢

转载自blog.csdn.net/bhliuhan/article/details/80345549
今日推荐