Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //查找字符是否出现
- #include <iostream>
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- int main(){
- int n,m;
- while(scanf("%d", &n)!=EOF){
- int a[10000];
- for(int i=0;i<n;i++){
- int tmp;
- cin>>tmp;
- a[tmp] = 1;
- }
- cin>>m;
- for(int i=0;i<m;i++){
- int tmp;
- cin>>tmp;
- if(a[tmp]==1) cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- }
- }
- //二分查找------------------------返回下标值
- int bsearchWithoutRecursion(int array[], int low, int high, int target)
- {
- while(low <= high)//记住=结束
- {
- int mid = low+(high-low)/2;
- if (array[mid] > target)
- high = mid - 1;
- else if (array[mid] < target)
- low = mid + 1;
- else //find the target
- return mid;
- }
- //the array does not contain the target
- return -1;
- }
Add Comment
Please, Sign In to add comment