题解 | #查找#
查找
http://www.nowcoder.com/practice/d93db01c2ee44e8a9237d63842aca8aa
#include<stdio.h> #include<stdbool.h> const int max=100; int arr[max]; bool linearsearch(int n,int target) { for(int i=0;i<n;i++) { if (arr[i]==target) { return true; } } return false; } int main() { int n,m; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&arr[i]); } scanf("%d",&m); while(m--) { int target; scanf("%d",&target); if (linearsearch(n,target)) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }