题解 | #查找#

查找

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

#include <iostream>
using namespace std;

int main() {
    int n, m,t;
    int a[100] = {0};
    int b=0;
    while (cin >> n) { // 注意 while 处理多个 case
        //将元素存入数组
        for(int i =0; i < n; i++)
        {
            cin >> t;
            a[t] = 1;   //利用数组进行统计是否出现  元素作数组下标
        }

        //比较输出
        cin >> m;
        for(int i = 0; i < m; i++)
        {
            cin >> b;
            if(a[b]==1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

空间换时间---元素作下标,判断出现与否

全部评论

相关推荐

见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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