UVa 10282 - Babelfish

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<sstream>

#define sf scanf
#define pf printf
#define high 100100

using namespace std;

typedef map<string , string>mpss;

mpss mp;

void storage(string x)
{
    int i=0 , len=x.length();

    string first="" , second="";

    while(x[i] != ' ')
    {
        first+=x[i];
        i++;
    }

    while(i < len)
    {
        if(x[i] != ' ')
        {
            second+=x[i];
        }

        i++;
    }

    mp[second] = first;
}


int main()
{
    string tmp;

    while(getline(cin , tmp))
    {
        if(tmp.length() == 0) break;

        storage(tmp);
    }

    string s;

    while(cin >> s)
    {
        if(!mp[s].size())
        {
            cout << "eh\n";
        }

        else
        {
            cout << mp[s] << "\n";
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number