CE求助

P2249 【深基13.例1】查找

sansesantongshun @ 2023-08-17 20:35:17

#include<bits/stdc++.h>
using namespace std;
int n,m,x,index;
vector<int> a;
int main()
{
    cin>>n>>m;
    while (n--)
    {
        scanf("%d",&x);
        a.push_back(x);
    }
    while (m--)
    {
        scanf("%d",&x);
        index=lower_bound(a.begin(),a.end(),x)-a.begin();
        if (index<a.size() && a[index]==x)
        cout<<index+1<<' ';
        else
        cout<<"-1 ";
    }
}

by EricQian0918 @ 2023-08-17 20:51:02

index是系统关键字,把它换个名字就AC了


|