题解 | #查找#

查找

https://www.nowcoder.com/practice/d93db01c2ee44e8a9237d63842aca8aa

#include "cstdio"
#include "map"

using namespace std;


int main() {
    int n, m;
    scanf("%d", &n);
    int arr[n + 1];
    map<int, int> findIndex;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &arr[i]);
        findIndex[arr[i]] = i;  // key 是元素 value是下标
    }
    scanf("%d", &m);
    int x;
    for (int i = 0; i < m; ++i) {
        scanf("%d", &x);
        if (findIndex.find(x) == findIndex.end()) {
            printf("NO\n");
        } else {
            printf("YES\n");
        }
    }
    return 0;
}

全部评论

相关推荐

昨天 12:09
郑州大学 Java
有啥题目啊?
投递小红书等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
09-09 15:13
李涛一下,如果只有大厂title但是全是dw,你们会去吗没有大厂的话对秋招影响大吗
代码不跑我跑_秋招版:你就不能做到既有title又包装得产出不错么,包装也是筛选人的一步。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务