11217: 【原1217】optimization
题目
题目描述
author: DS TA 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1217
Description
给定一个大小为 n 的无序表(元素为整数),询问 m 次,回答是否找到询问的元素。
Input Format
第 1 行: 一个数, n
第 2 行: n 个数, 给定这个无序表的所有元素。
第 3 行: 一个数, m
第 4 行: m 个数, 每个数表示这次询问的元素。
Output Format
输出共 m 行,每行一个字符(Y/N),表示是否找到询问的元素。
Sample Input:
5
42 43 42 44 45
5
42 42 44 88 100
Sample Output:
Y
Y
Y
N
N
Limits
n, m <= 2500
ligongzzz's solution
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
unordered_map<int, bool> mdata;
for (; n; --n) {
int temp;
cin >> temp;
mdata.insert(make_pair(temp, true));
}
int m;
cin >> m;
for (; m; --m) {
int temp;
cin >> temp;
if (mdata.find(temp) != mdata.end())
cout << "Y\n";
else
cout << "N\n";
}
return 0;
}