Problem J: STL——字典

xiaoxiao2021-02-28  111

HomeWeb BoardProblemSetStandingStatusStatistics

Problem J: STL——字典

Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 5865  Solved: 1090 [ Submit][ Status][ Web Board]

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

5dog ogdaycat atcaypig igpayfroot ootfrayloops oopslay3atcayittenkayoopslay

Sample Output

catehloops

HINT

用STL的map容易实现

Append Code

[ Submit][ Status][ Web Board]

한국어<   中文  فارسی  English  ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin

#include <iostream> #include <algorithm> #include <map> using namespace std; int main() { std::ios::sync_with_stdio(false);//减少时间防止超时 string a, b; map <string,string > A; int n; while(cin >> n) { for(int i = 0; i < n; i++) { cin >> b>> a; A.insert(make_pair(a, b)); } int m; cin >> m; for(int i = 0; i < m; i++) { string c; cin >> c; map<string,string> :: iterator ite; ite = A.find(c); if(ite != A.end() ) cout << ite -> second << endl; else cout << "eh" << endl; // pair<map<string,string>::iterator,map<string,string>::iterator> ite; // ite=A.equal_range(c); // if( ite.first->first == c ) // cout << ite.first->second << endl; // else // { cout << "eh " << ite.first->first << endl; } } A.clear(); } }
转载请注明原文地址: https://www.6miu.com/read-44829.html

最新回复(0)