// An highlighted block
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
using namespace std;
void read_data(unordered_map<string, int>& vocab, string& str);
void printword(unordered_map<string, int>& vocab, const string& target_str);
int main()
{
unordered_map<string, int> vocabulary;
string target_str;
read_data(vocabulary, target_str);
printword(vocabulary, target_str);
}
void read_data(unordered_map<string, int>& vocab, string& str)
{
char ch = ' ';
while (ch!='#')
{
string s;
getline(cin, s);
if (s.empty())
{
ch = '#';
}else
vocab[s]++;
}
getline(cin, str);
}
void printword(unordered_map<string, int>& vocab, const string& s)
{
int left = 0, right = 0;
while (left < s.size())
{
bool hasfind = false;
for (right = left; right < s.size(); right++)
{
string str = s.substr(left, right - left+1);
if (vocab.count(str)==1)
{
vocab[str]++;
cout << str << " " << left << " " << right << endl;
hasfind = true;
break;
}
}
if (hasfind)
{
right++;
left = right;
}
else
{
left++;
}
//cout << "left:" << left << endl;
}
}
敏感词查找
最新推荐文章于 2023-11-30 11:20:59 发布