You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
C++

#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
using namespace std;
int main()
{
string s, word, word2;
istringstream ss;
int n;
getline(cin, s);
ss = istringstream(s);
ss >> n;
unordered_map<string, string> M;
while (n--)
{
getline(cin, s);
for (auto &ch : s)
if ('A' <= ch && ch <= 'Z')
ch = ch - 'A' + 'a';
//cout << "*** " << s << endl;
ss = istringstream(s);
string name, word;
ss >> name;
while (ss >> word)
M[word] = name;
}
while (getline(cin, s))
{
for (auto &ch : s)
if (ch == ',' || ch == '.' ||
ch == '(' || ch == ')' ||
ch == '[' || ch == ']' ||
ch == '{' || ch == '}' ||
ch == '<' || ch == '>' ||
ch == ';' || ch == '!' ||
ch == '?')
ch = ' ';
else if ('A' <= ch && ch <= 'Z')
ch = ch - 'A' + 'a';
ss = istringstream(s);
while (ss >> word)
{
auto ite = M.find(word);
if (ite != M.end())
{
cout << ite->second << endl;
goto outer;
}
}
outer:;
}
return 0;
}