POJ3253Babelfish

http://poj.org/problem?id=3253

就是一个哈夫曼树,题目下边有提示,所以题意还是好理解的

#include<cstdio>

#include<cstring>

#include<iostream>

#include<map>

using namespace std;

int main ()

{

    map<string, string> tra;

    char s[100011], str[100011], s1[100011];

    while (gets(s)&&s[0])

    {

        sscanf(s,"%s %s",str,s1);//将输入的字符串,空格前边的赋给str串,后边的赋给s1串

        tra.insert(pair<string,string>(s1,str));

    }

    while(cin>>str)

    {

        if (tra.find(str) != tra.end())

            cout<<tra[str]<<endl;

        else

            cout<<"eh"<<endl;

    }

    return 0;

} 
View Code

 

你可能感兴趣的:(poj)