题目1168:字符串的查找删除
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:6018
解决:2503
-
题目描述:
-
给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。
-
输入:
-
输入只有1组数据。
输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。
-
输出:
-
删除输入的短字符串(不区分大小写)并去掉空格,输出。
-
样例输入:
-
in #include int main() { printf(" Hi "); }
-
样例输出:
-
#clude tma() { prtf("Hi"); }
-
提示:
-
注:将字符串中的In、IN、iN、in删除。
-
来源:
- 2009年北京航空航天大学计算机研究生机试真题
-
#include<stdio.h> #include<iostream> #include<stdlib.h> #include<string.h> #include<string> #include<ctype.h> using namespace std; int main() { char str[100]={0}; char str1[100]={0}; gets(str); string a=str; for(int i=0;i<a.size();i++) { a[i]=toupper(a[i]); } while(gets(str1)){ string b=str1; for(int i=0;i<b.size();i++) { b[i]=toupper(b[i]); } string c=str1; int t=0; t=b.find(a,0); while(t!=string::npos){ c.erase(t,a.size()); b.erase(t,a.size()); t=b.find(a,0); } //cout<<c<<endl; for(int i=0;i<c.size();i++) { if(c[i]!=' ') cout <<c[i]; } cout<<endl; } system("pause"); return 0; }