查找练习 hash——出现过的数字

本题对于按照学习顺序来做的同学而言,没有太多可以讲解的地方,

所以直接上代码喽

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int a[100000+10];
 4 int main()
 5 {
 6     int n,m,i,x;
 7     scanf("%d%d",&n,&m);
 8     for(i=0;i<100010;i++)
 9         a[i]=0;
10     for(i=0;i<n;i++)
11     {
12         scanf("%d",&x);
13         a[x]++;
14     }
15     while(m--)
16     {
17         scanf("%d",&x);
18         if(a[x]!=0)printf("YES\n");
19         else printf("NO\n");
20     }
21     return 0;
22 }
23 
24 
25 /***************************************************
26 Result: Accepted
27 Take time: 48ms
28 Take Memory: 536KB
29 ****************************************************/

猜你喜欢

转载自www.cnblogs.com/xqmmd/p/9484638.html