Responsive image

问题 G: 第7关:字符串的插入

问题 G: 第7关:字符串的插入

时间限制: 1 Sec  内存限制: 128 MB
提交: 0  解决: 2
[提交][状态][讨论版][命题人:]

题目描述

编写算法,实现下面函数的功能。函数void insert(char * s,char * t,int pos)将字符串t插入到字符串s中,插入位置为pos(插在第pos个字符前)。假设分配给字符串s的空间足够让字符串t插入。(说明:不得使用任何库函数)
#include<iostream>
#define MAXSIZE 100
using namespace std;
void Insert(char s[],char t[],int pos,int LenS,int LenT)
{//字符串的插入
/**************begin************/





    /**************end************/
}
int main()
{
    int pos;
    while(cin>>pos)            //输入插入位置pos
    {
        if(pos<=0) break;
        char s[MAXSIZE],t[MAXSIZE];
        cin>>s>>t;                 //输入字符串s和t
        int LenS=0,LenT=0;
        while(s[LenS]!='\0') LenS++;           //求字符串s的长度LenS
        while(t[LenT]!='\0') LenT++;          //求字符串t的长度LenT
        if(pos>LenS) break;       //插入位置非法
        Insert(s,t,pos,LenS,LenT);
    }
    return 0;
}



输入描述

多组数据,每组数据有三行,第一行为插入的位置pos,第二行为要被插入的字符串s,第三行为待插入的字符串t。当pos为“0”时输入结束。

输出描述

对于每组数据输出一行,为t插入s后的字符串。

样例输入

1
abcde
abc
2
acd
baaaa
0

样例输出

abcabcde
abaaaacd

提示


组合提交代码,你仅需要提交





void Insert(char s[],char t[],int pos,int LenS,int LenT)


{//字符串的插入


/**************begin************/














    /**************end************/


}




[提交][状态]
ACM算法攻关部
  • Anything about this OnlineJudge, Please Contact Administrator. Click add QQ

    OJ system based on HUSTOJ Project , UI based on Twitter Bootstrap

    Copyright 2016 ACM算法攻关部
    关于网站改版