自己看
2026-08-18 10:34:42
发布于:广东
0阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[110];
ll x;
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
cin>>n;
for(ll i=1;i<=n;i++) cin>>a[i];
cin>>x;
ll l=1,r=n;
while(l<=r){
ll mid=l+r>>1;
if(a[mid]==x){
cout<<mid<<endl;
return 0;
}else{
if(a[mid]>x){
r=mid-1;
}else{
l=mid+1;
}
}
}
cout<<-1<<endl;
//fclose(stdin);
//fclose(stdout);
return 0;
}
//coder::by::M91
这里空空如也






有帮助,赞一个