4323: 【入门】数字查询(1762)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:20 解决:13

题目描述

有 lns="http://www.w3.org/1998/Math/MathML"> 个同学,每个同学的名字用一个英文小写字母的字符串表示,所有同学名字互不相同,并为每个同学分配一个数字。

给出 lns="http://www.w3.org/1998/Math/MathML"> 次询问,每次询问给出一个同学的名字,请求出该同学分配到的数字是多少?

【数据范围】

对于 100% 的数据,字符串仅包含小写字母,字符串长度在 [1,20] 的范围内,1,104

每位同学分配到的数字在 [1,104] 的范围内,测试数据保证所有的名字不重复,  次询问的名字一定存在。

输入

第 lns="http://www.w3.org/1998/Math/MathML">1 行 lns="http://www.w3.org/1998/Math/MathML"> ,lns="http://www.w3.org/1998/Math/MathML"> 。

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行有一个英文字母构成的字符串,以及一个数字,中间用空格隔开;

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行一次询问,代表一个同学的名字。

输出

输出 lns="http://www.w3.org/1998/Math/MathML"> 行,每行输出询问同学名字对应的数字。

样例输入 复制

5 3
alice 3
jack 4
smith 88
bob 100
wangfang 500
jack
alice
smith

样例输出 复制

4
3
88

提示

#include<bits/stdc++.h>
using namespace std;
map<string,int> m;
int n,q;
int main(){
    string s1;
    int t;
    cin>>n>>q;
    while(n--) {
    	cin>>s1>>t;
    	m[s1] = t;
    }
    while(q--) {
        cin>>s1;
        cout<<m[s1]<<endl;
    }
    return 0;
}