编辑代码

#include <iostream>
using namespace std;
void insert(char *s,char *t,int pos){
    if(pos<1)   return;
    int i=0,j=0;
    while(s[i]&&i<pos-1)//只能在1<=pos<=总长度+1处插入
        i++;
    if(!s[i]){
        cout<<"dayu";
        return;
    }
    while(s[i])
        i++;
    while(t[j])
        j++;
    for(;i>=pos;i--){
        s[i+j-1] =s[i-1];
    }
    for(int n=0;n<j;n++){
        s[i++] = t[n];
    }
    i=0;
    while(s[i]){
        cout<<s[i]<<endl;
        i++;
    }
}
int main() {
    char s[10]={'a','b','c','d'};
    char t[3]={'f','g'};
    int i=0;
    insert(s,t,2);
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
	return 0;
}