OJ 1353 Problem F STL——字典

Description

输入n个字符串对(str1,str2),再输入k个查询字符串str,从字符串对中查找查询字符串,即如果str=str2,则输出str1,如果查询不到则输出"eh"(不包含引号)。输入保证所有字符串对的str2不相同,字符串只含有字母和数字,长度小于20!

Input

输入包含多组数据,直到文件结尾。

每组数据第一行包含一个整数n(0≤n≤10^5)。接下来n行,每行描述一个字符串对。

接下来包含一个整数m(0≤m≤10^5)。接下来m行,每行描述一个查询字符串。

见样例

Output

输出每个查询的结果。

Sample Input

5
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
3
atcay
ittenkay
oopslay

Sample Output

cat
eh
loops

HINT

用STL的map容易实现

Accepted Code

#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <string>
#include <set>
#include <cstdio>
#include <iomanip>
using namespace std;

int main() {
    int n = 0;
    //有多组数据
    while (cin >> n) {
        map<string, string> s;
        while (n--) {
            string str1, str2;
            cin >> str1 >> str2;
            s[str2] = str1;
        }
        int m = 0;
        cin >> m;
        while (m--) {
            string str;
            cin >> str;
            //map的查找方法
            map<string, string> :: iterator iter;
            iter = s.find(str);
            if(iter != s.end()) cout << iter->second << endl;
            else cout << "eh" << endl;
        }
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值