天天看點

Babelfish POJ 2503 map映射

這題題意很簡單 思路也很簡單看完題基本都懂

一開始看覺得用map很簡單

後來發現用map的話讀入啥的很頭疼

最後寫的時候确實很折磨

看了題解才知道怎麼寫

字典樹寫法晚點學會了在加上

ac代碼

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#define pi 3.1415926535898
#define ll long long
#define lson rt<<1
#define rson rt<<1|1
#define eps 1e-6
#define ms(a,b) memset(a,b,sizeof(a))
#define legal(a,b) a&b
#define print1 printf("111\n")
using namespace std;
const int maxn = 5e5+10;
const int inf = 0x3f3f3f3f;
const ll llinf =0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;

map<string,string>mp;

int main()
{
    char str[50],str2[15],str1[15];
    while(gets(str))
    {
        if(strlen(str)==0)
            break;
        sscanf(str,"%s%s",str1,str2);
        mp[str2]=str1;
    }
    string s;
    while(cin>>s)
    {
        string tem=mp[string(s)];
        if(tem.length()==0)
            cout<<"eh"<<endl;
        else
            cout<<tem<<endl;
    }
}