查找练习 hash——出现过的数字
来源:互联网 发布:药品销售数据分析 编辑:程序博客网 时间:2024/04/28 09:45
查找练习 hash——出现过的数字
题目描述
有一个数据字典,里面存有n个数字(n<=100000),小明现在接到一个任务,这项任务看起来非常简单——给定m个数字,分别查询这m个数字是否出现在字典之中;但是考虑到数据量的问题,小明找到了善于编程的你,希望你可以帮他解决这个问题。
输入
输入数据只有一组!
第一行包含两个整数n m,分别代表字典中数字的个数和要查询的数字的个数。
接着n行代表字典中的n个数字。
最后m表示要查询的数字。
输出
如果某个数字存在,则输出YES,否则输出NO
示例输入
5 3123455410
示例输出
YESYESNO
#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<malloc.h>#include<stack>using namespace std;int main(){ int n,m,i,j; int a[100001],b[100001],c[100001]; memset(c,0,sizeof(c)); cin>>n>>m; for(i=1;i<=n;i++) { cin>>a[i]; c[a[i]]=1; } for(j=1;j<=m;j++) { cin>>b[j]; if(c[b[j]]==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; }}
0 0
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- SDUT 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- sdut2123查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- sdut查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 查找练习 hash——出现过的数字
- 中值滤波讲解-Matlab
- [leetcode]Add Two Numbers
- vcenter
- RHEL分区与格式化、挂载以及文件系统优化
- Image I/O 编程指引
- 查找练习 hash——出现过的数字
- C/C++求职宝典21个重点笔记(常考笔试面试点)
- MFC中的MainFrame Dlg,App,Doc,View的关系
- 统计元音
- linux进程间消息队列通信
- 一些学到的东西
- 第14周OJ平台项目——杨辉三角
- Python笔记-排序算法实现(1)
- 使用ViewPager时报出The application’s PagerAdapter changed the adapter’s contents without calling PagerAda