您的位置:首页 > 其它

题目1168:字符串的查找删除

2014-03-11 16:02 417 查看
题目描述:

给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。

输入:

输入只有1组数据。

输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。

输出:

删除输入的短字符串(不区分大小写)并去掉空格,输出。

样例输入:
in
#include
int main()
{

printf(" Hi ");
}


样例输出:
#clude
tma()
{

prtf("Hi");
}


class App{
private :
string word  ;
string text  ;
public :
App() ;
App(string w , string t):word(w) , text(t){
gao() ;
}
int judge(int index) ;
void brush(int index) ;
void gao() ;
friend ostream & operator << (ostream&  , const App & ) ;
};

int App::judge(int index){
int i = index ;
int j = 0 ;
while(i < text.length() && j < word.length()){
if(text[i] == word[j]){
i++ ;
j++ ;
}
else
return 0 ;
}
return j == word.length() ;
}

void App::brush(int index){
int j = index ;
for(int i = 0  ; i < word.length() ; i++)
text[j++] = ' ' ;
}

void App::gao(){
for(int i = 0 ; i < text.length() ; i++){
if(judge(i))
brush(i) ;
}
}

ostream & operator << (ostream& out , const App & now){
for(int i = 0 ; i < now.text.length() ; i++)
if(now.text[i] != ' ')
cout<<now.text[i] ;
return out ;
}

int main(){
string word , text;
cin>>word ;
getchar() ;
while(getline(cin ,text)){
App * app = new App(word, string(text))  ;
cout<<(*app)<<endl ;
delete app ;
}
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: