Algorithm


 problem Link : https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1217 

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them. Input Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters. Output Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as ‘eh’.

Sample Input dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay

Sample Output cat eh loops

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include <iostream>
#include <sstream>
#include <iomanip>
#include <unordered_map>

using namespace std;

int main()
{
    string in1,in2;
    unordered_map < string,string> trans;
    while(getline(cin,in1), !in1.empty()){
        istringstream iss(in1);
        iss >> in1 >> in2;
        trans[in2] = in1;
    }
    while(cin >> in1){
        if(trans.count(in1)) cout << trans[in1] << endl;
        else cout << "eh" << endl;
    }
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 2
administer 100000
spending 200000
manage 50000
responsibility 25000
expertise 100
skill 50
money 75000
the incumbent will administer the spending of kindergarden milk money
and exercise responsibility for making change he or she will share
responsibility for the task of managing the money with the assistant
whose skill and expertise shall ensure the successful spending exercise
. this individual must have the skill to perform a heart transplant and expertise in rocket science

Output

x
+
cmd
cat
eh
loops
Advertisements

Demonstration


UVA Online Judge solution - 10282 - Babelfish - UVA Online Judge solution in C,C++,java                      

Previous
UVA Online Judge solution - 10276 - Hanoi Tower Troubles Again - UVA Online Judge solution in C,C++,java !
Next
UVA Online Judge solution - 10295 - Hay Points - UVA Online Judge solution in C,C++,java