救助!!!

P2249 【深基13.例1】查找

xingff @ 2024-08-05 17:15:25

#include <bits/stdc++.h>
using namespace std;
vector<int> a;
void search(int q)
{
    auto pos=lower_bound (a.begin(),a.end(),q);
    if (*pos!=q)printf("-1\n");
    else cout<<pos-a.begin()+1<<endl;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k;
        a.push_back(k);
    }
    for(int i=1;i<=m;i++)
    {
        int p;
        cin>>p;
        search(p);
    }
    return 0;
}

by ZeroOf149 @ 2024-08-05 17:18:44

输出是用空格分开(而不是换行)


by ouxiyao @ 2024-08-07 08:49:17

cin爆!


by heimingyang @ 2024-08-14 16:05:28

@xingff 输入用scanf("%d",&k);


by xingff @ 2024-08-14 17:39:45

蟹蟹


|