Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. //查找字符是否出现
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <algorithm>
  5. using namespace std; 
  6. int main(){
  7.     int n,m;
  8.     while(scanf("%d", &n)!=EOF){
  9.         int a[10000];
  10.         for(int i=0;i<n;i++){
  11.             int tmp;
  12.             cin>>tmp;
  13.             a[tmp] = 1;
  14.         }
  15.         cin>>m;
  16.         for(int i=0;i<m;i++){
  17.             int tmp;
  18.             cin>>tmp;
  19.             if(a[tmp]==1) cout<<"YES"<<endl;
  20.             else cout<<"NO"<<endl;
  21.         }
  22.     }
  23. }
  24. //二分查找------------------------返回下标值
  25. int bsearchWithoutRecursion(int array[], int low, int high, int target)
  26. {
  27. while(low <= high)//记住=结束
  28. {
  29. int mid = low+(high-low)/2;
  30. if (array[mid] > target)
  31. high = mid - 1;
  32. else if (array[mid] < target)
  33. low = mid + 1;
  34. else //find the target
  35. return mid;
  36. }
  37. //the array does not contain the target
  38. return -1;
  39. }
Add Comment
Please, Sign In to add comment