有大佬可以帮帮我吗?为什么不输出啊

P2249 【深基13.例1】查找

wenchuang @ 2023-12-05 20:21:44

这段代码为什么不输出啊?

#include<cstdio>
using namespace std;
int main(){
    int n1,n2;
    scanf("%d",&n1);
    scanf("%d",&n2);
    int a[n1+1];
    int x[n2+1];
    for(int i=0;i<n1;i++){
        scanf("%d",&a[i]);
    }

    for(int i=0;i<n2;i++){
        scanf("%d",&x[i]);
    }
    int b=n1-1,s=0,q;
    for(int i=0;i<n2;i++){
        for(int j=0;j<n1;j++){
            q=(b+s)/2;
            if(a[q]>x[i]){
                a[q]=b;
            }else if(a[q]<x[i]){
                a[q]=s;
            }else if(a[q]==x[i]&&a[q-1]!=a[q]){
                printf("%d ",a[q]);
                break;
            }else{
                printf("-1");
                break;
            }
        }
    }
    return 0;
}

|