不知道哪里写错了 萌新求助555

P2249 【深基13.例1】查找

Flurry35263 @ 2024-01-16 21:17:20

#include <stdio.h>
int Find(int wait[],int find,int left,int right);
int main(){
    int n,m,i,find;
    scanf("%d %d",&n,&m);
    int wait[1000050];
    for(i=0;i<n;i++)
        scanf("%d",&wait[i]);
    for(i=0;i<m;i++){
        scanf("%d",&find);
        int tmp=Find(wait,find,0,n-1);
        printf("%d ",tmp+1);
    }
    return 0;
}
int Find(int wait[],int find,int left,int right){
    if(left<=right){
        int mid=(left+right)/2;
        if(find==wait[mid])
            return mid;
        else if(find<wait[mid])
            return Find(wait,find,left,mid-1);
        else
            return Find(wait,find,mid+1,right);
    }
    else
        return -2;
}

by Wang_ziao @ 2024-01-16 21:19:48

低调


|