报错求助

P2249 【深基13.例1】查找

Fzl2004 @ 2024-08-22 17:35:27


#include<bits/stdc++.h>

using namespace std;

using namespace std;

int search(int *nums, int target,int m,int n) {
        int min = m, max = n;
        int mid;
        while(min < max){
            mid = (min+max)/2;
            if(nums[mid]>target)max=mid-1;
            else if(nums[mid]<target)min=mid+1;
            else {
                while(nums[mid-1]==target)mid--;
                return mid+1;
            }
        }
        return -1;
}
int main(){
    int n,m;
    cin>>n>>m;
    int a[n+1],b[m+1];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    int x;
    for(int j = 0; j < m; j++){
        cin>>x;
        b[j] = search(a,x,0,n);
    }
    for(int k = 0; k < m; k++){
        cout<<b[k]<<" ";
    }
    return 0;
}
 ``` ```

by dream_dad @ 2024-08-22 17:45:41


using namespace std;
多了1个

|