题目1168:字符串的查找删除
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:2801
解决:1103
-
题目描述:
-
给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。
-
输入:
-
输入只有1组数据。
输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。
-
输出:
-
删除输入的短字符串(不区分大小写)并去掉空格,输出。
-
样例输入:
-
in #include int main() { printf(" Hi "); }
-
样例输出:
-
#clude tma() { prtf("Hi"); }
-
提示:
-
注:将字符串中的In、IN、iN、in删除。
-
来源:
- 2009年北京航空航天大学计算机研究生机试真题
-
- c++代码:
-
//1168 字符串的查找删除 #include<string> #include<iostream> using namespace std; int main(void) { string rst, mst; getline(cin, rst); int r_len = rst.length(); cout<<"";//清空cin缓冲区 while(getline(cin, mst)) { //去空格 for(string::size_type index=0; index!=mst.size(); ++index) { if(isspace(mst[index])) mst.erase(index--,1); } int pos = mst.find(rst); while(pos!=-1) { mst.replace(pos, r_len, ""); pos = mst.find(rst); } cout << mst; if(mst.find("\n")==-1) cout << endl; } return 0; }