[百度]敏感詞
阿新 • • 發佈:2018-12-12
題目描述
大部分論壇、網站等,為了方便管理,都進行了關於敏感詞的設定。
在多數網站,敏感詞一般是指帶有敏感政治傾向、暴力傾向、不健康色彩的詞或不文明語,也有一些網站根據自身實際情況,設定一些只適用於本網站的特殊敏感詞。比如,當你發貼的時候帶有某些事先設定的詞時,這個貼是不能發出的。或者這個詞被自動替換為星號 (*),或者說是被和諧掉了。請注意敏感詞只有小寫字母,文字如果中的大寫字母當做小寫字母處理,出現敏感單詞,即使作為子串出現也要被和諧,多個子串重疊他們都要被和諧。
例如當敏感詞是gre,eat 是
Your English is Great.
將被和諧成
Your English is *****.
請程式設計,輸入給定的文字和關鍵字,將所有被和諧的部分都打上星號 (*)
輸入
輸入的第一行包含一個整數 n,表示敏感詞的總數。 接下來的 n 行,每行包含一個長度不超過 100 的敏感詞,單詞不區分大小寫。 接下來的一行包含一段長度不超過 10000的字串表示待處理的文字。 |
樣例輸入
4 revolution greatwall democracy science Cross the greatwall, we can reach every corner of the world. |
輸出
輸出一行,表示和諧過後的文字。 |
樣例輸出
Cross the *********, we can reach every corner of the world. |
時間限制C/C++語言:1000MS其它語言:3000MS |
記憶體限制C/C++語言:65536KB其它語言:589824KB |
#include <stdio.h> #include <cstdio> #include <vector> #include <string> #include <iostream> using namespace std; int main() { int T = 0; cin >> T; vector<string> grepList; for( int i = 0;i < T;++i ){ string str; cin >> str; grepList.push_back( str ); } string strOrg = "", strRet; getline( cin, strOrg ); getline( cin, strOrg ); strRet = strOrg; for( int i = 0;i < strOrg.length();++i ){ if( strOrg[i] >= 'A' && strOrg[i] <= 'Z' ){ strOrg[i] += 'a' - 'A'; } } for( int i = 0;i < grepList.size();++i ){ int offset = 0; while( offset < strOrg.size() ){ int pos = strOrg.find( grepList[i], offset ); if( pos == string::npos )break; for( int j = pos;j < pos + grepList[i].length();++j ){ strRet[j] = '*'; } offset = pos + grepList[i].length(); } } cout<<strRet<<endl; return 0; }