九度OJ1049题-去特定字符(和1111题特别像)

题目1049:字符串去特定字符

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:11329

解决:5169

题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入:

测试数据有多组,每组输入字符串s和字符c。

输出:

对于每组输入,输出去除c字符后的结果。

样例输入:
heallo
a
样例输出:
hello
来源:
2009年哈尔滨工业大学计算机研究生机试真题
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string>
 4 #include <ctype.h>
 5 using namespace std;
 6 
 7 int main()    {
 8     char stra[201];
 9     while(gets(stra)){
10         string a = stra;
11         char strb[201];
12         gets(strb);
13         string b = strb;
14 
15         int pos = a.find(b, 0);
16         while(pos != string::npos)    {
17             a.erase(pos, b.size());
18             pos = a.find(b, pos);
19         }
20         cout << a << endl;
21     }
22 
23     return 0;
24 
25 }
原文地址:https://www.cnblogs.com/QingHuan/p/6978655.html