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;
    }
}

猜你喜欢

转载自blog.csdn.net/daydreamer23333/article/details/107465194
今日推荐