厦大C语言上机 1491 子串删除
2018-01-14 11:28
1006 查看
1491.子串删除
时间限制: 1000 MS 内存限制: 65536 K
提交数: 400 (0 users) 通过数: 211 (203 users)
问题描述
给定两个字符串s和t,若s是t的子串,将t中的子串s删除,若存在多个子串,则全部删除;若s不是t的子串,对字符串t不做处理。字符串s和t长度不超过1000。
输入格式
第一行,字符串t,文本长度<=1000。
第二行,字符串s,文本长度<=1000。
输出格式
处理后的字符串t
样例输入
Hello World!
Hello
Hello World!
Ho
No pain, no gain
ain
样例输出
World!
Hello World!
No p, no g
来源
xmu
时间限制: 1000 MS 内存限制: 65536 K
提交数: 400 (0 users) 通过数: 211 (203 users)
问题描述
给定两个字符串s和t,若s是t的子串,将t中的子串s删除,若存在多个子串,则全部删除;若s不是t的子串,对字符串t不做处理。字符串s和t长度不超过1000。
输入格式
第一行,字符串t,文本长度<=1000。
第二行,字符串s,文本长度<=1000。
输出格式
处理后的字符串t
样例输入
Hello World!
Hello
Hello World!
Ho
No pain, no gain
ain
样例输出
World!
Hello World!
No p, no g
来源
xmu
#include <stdio.h> #include <string.h> void delete_substring(char *t, char *s, char *output) { int len_t = (int)strlen(t); int len_s = (int)strlen(s); int ptr_t, ptr_s, ptr_output, ptr_temp; ptr_t = 0; ptr_output = 0; while (ptr_t < len_t) { ptr_temp = ptr_t; ptr_s = 0; while (ptr_temp < len_t && ptr_s < len_s) { if (t[ptr_temp] != s[ptr_s]) break; ptr_temp++; ptr_s++; } if (ptr_s == len_s) ptr_t += len_s; else output[ptr_output++] = t[ptr_t++]; } output[ptr_output] = '\0'; } int main() { char t[1005] = { 0 }; char s[1005] = { 0 }; char output[1005] = { 0 }; while (gets(t)) { gets(s); delete_substring(t, s, output); printf("%s\n", output); } return 0; }
相关文章推荐
- 厦大C语言上机 1381 不重叠子串数
- 厦大C语言上机 1503 字符串处理
- 5-29 删除字符串中的子串 (20分)c语言
- 厦大C语言上机 1400 出队统计
- 厦大C语言上机 1374 进制转换
- 厦大C语言上机 1385 石子消耗游戏
- 厦大C语言上机 1484 成绩统计
- 厦大C语言上机 1495 亲密对数
- 厦大C语言上机 1504 整数编号
- 厦大C语言上机 1377 寻书之旅1
- 厦大C语言上机 1387 进制转换进阶版
- 厦大C语言上机 1485 成绩排序
- 厦大C语言上机 1388 高精度乘法
- 厦大C语言上机 1486 第K高的人
- c语言练习 10-2. 删除字符串中的子串(20)
- C语言字符串操作--删除子串
- C语言字符串操作--删除子串
- C语言——删除字符串中的指定子串
- 厦大C语言上机 1265 字符串后继
- 厦大C语言上机 1389 简单的统计