题解
2024-10-13 16:01:55
发布于:广东
1阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
int n,x;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
cin >> x;
int ans = -1;
int left = 1,right = n;
while(left <= right){
int mid = (left + right) / 2;
if(a[mid] > x){
ans = mid;
right = mid - 1;
}else{
left = mid + 1;
}
}
cout << ans;
return 0;
}
这里空空如也
有帮助,赞一个