#include <iostream>
#include <sstream>
#include <string>
#include <map>
using namespace std;
string getFileData()
{
string data;
data += "6\n";
data += "b\n"; data += "Second Letter in the Alphabet (Rhymes with 'Bee')\n";
data += "a\n"; data += "The first letter in the alphabet (Vowel)\n";
data += "why\n"; data += "Why what?\n";
data += "why?\n"; data += "Why what?\n";
data += "hello\n"; data += "Hello!\n";
data += "hi\n"; data += "Hello!\n";
return data;
}
int main()
{
// let's pretend this is our file
stringstream file(getFileData());
int n;
file >> n; // get number of entries
file.get(); // ignore newline
map<string, string> dataMap;
for (int i = 0; i < n; ++ i)
{
string key, value;
getline(file, key);
getline(file, value);
dataMap[key] = value;
}
// no need to sort. map
// sorts automatically by key
string input;
while (true)
{
getline(cin, input);
if (input.empty()) break; // empty line == quit
// make everything lowercase
for (int i = 0; i < input.length(); ++ i)
if (input[i] >= 'A' && input[i] <= 'Z')
input[i] += 'a' - 'A';
// if the key exists, print the respective value
if (dataMap.find(input) != dataMap.end())
cout << dataMap[input] << endl;
// otherwise, print an error message
else cout << "Sorry, I don't understand..." << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPG1hcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgZ2V0RmlsZURhdGEoKQp7CiAgICBzdHJpbmcgZGF0YTsKCiAgICBkYXRhICs9ICI2XG4iOwoKICAgIGRhdGEgKz0gImJcbiI7IGRhdGEgKz0gIlNlY29uZCBMZXR0ZXIgaW4gdGhlIEFscGhhYmV0IChSaHltZXMgd2l0aCAnQmVlJylcbiI7CiAgICBkYXRhICs9ICJhXG4iOyBkYXRhICs9ICJUaGUgZmlyc3QgbGV0dGVyIGluIHRoZSBhbHBoYWJldCAoVm93ZWwpXG4iOwogICAgZGF0YSArPSAid2h5XG4iOyBkYXRhICs9ICJXaHkgd2hhdD9cbiI7CiAgICBkYXRhICs9ICJ3aHk/X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ykKICAgICAgICAgICAgICAgIGlucHV0W2ldICs9ICdhJyAtICdBJzsKCiAgICAgICAgLy8gaWYgdGhlIGtleSBleGlzdHMsIHByaW50IHRoZSByZXNwZWN0aXZlIHZhbHVlCiAgICAgICAgaWYgKGRhdGFNYXAuZmluZChpbnB1dCkgIT0gZGF0YU1hcC5lbmQoKSkKICAgICAgICAgICAgY291dCA8PCBkYXRhTWFwW2lucHV0XSA8PCBlbmRsOwogICAgICAgIC8vIG90aGVyd2lzZSwgcHJpbnQgYW4gZXJyb3IgbWVzc2FnZQogICAgICAgIGVsc2UgY291dCA8PCAiU29ycnksIEkgZG9uJ3QgdW5kZXJzdGFuZC4uLiIgPDwgZW5kbDsKICAgIH0KfQ==