Description
实现在任给的串s中某位置p(0<p<=串S长度)之处插入另一任给的串as.
Input
主串s
子串as
位置p
Output
新主串(答案后不用换行回车)
Sample Input
ae f bcd 2
Sample Output
abcde f
Source: #include<iostream> using namespace std; char str[1000]; char sub[1000]; int p; void fun() { int i,j; int la,lb; la=strlen(str); lb=strlen(sub); for(i=la-1;i>=p-1;i--) { str[i+lb]=str[i]; } for(i=p-1,j=0;sub[j]!='/0';i++,j++) { str[i]=sub[j]; } } int main() { gets(str); gets(sub); cin>>p; fun(); cout<<str; } |