Problem : 从指定位置删除指定长度的字符串(串)

时间:2021-07-29 10:56:26
/*Description 从一个字符串中的第p个位置起删除指定长度的字符串,输出最终结果,若输入不合法,则输出 Illegal input Input 输入一个字符串s、位置p、长度n Output 删除子串后的字符串 Sample Input adfasdf12 6 5 Sample Output Illegal input HINT*/ #include <stdio.h> #include <stdlib.h> #include<string.h> int main() { char str1[100]; int a,b; int i,c; gets(str1); scanf("%d %d",&a,&b); c=strlen(str1); if(b>c-a-1||a>c-1) printf("Illegal input\n"); else { for(i=0;i<a;i++) printf("%c",str1[i]); for(i=a+b;i<c;i++) printf("%c",str1[i]); } return 0; }运行结果: