hermione_wqx @ 2024-07-26 20:34:27
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
int a[n],b[m],s[m];
memset(s, -1, sizeof(s));
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
for(int j=0;j<n;j++){
if(a[j]==b[i]){
s[i]=j+1;
break;
}
}
}
for(int i=0;i<m;i++){
cout<<s[i]<<" ";
}
return 0;
}
by liubaicheng444 @ 2024-07-26 20:35:45
@hermione_wqx 成功入门!恭喜
by hermione_wqx @ 2024-07-26 20:37:24
@liubaicheng444 ???
by __D_A_T__ @ 2024-07-26 20:39:36
有没有一种可能,这题正解是二分查找而不是循环
by exCat @ 2024-07-26 20:40:38
@hermione_wqx 你的做法是
by hermione_wqx @ 2024-07-26 20:41:29
好的,谢谢dalao!!!马上改
by hermione_wqx @ 2024-07-26 20:44:23
@D_A_T @IOI_AKME 谢谢谢谢
by KXY_Moon @ 2024-07-26 20:52:13
@hermione_wqx
by ouxiyao @ 2024-08-07 08:24:42
lower_bound会用吗?