题解
2026-09-30 14:25:35
发布于:浙江
6阅读
0回复
0点赞
这道题很简单,直接用lower_bound就好了。
二话不说直接上代码:
#include<bits/stdc++.h>
using namespace std;
int a[105];//因为1≤n≤100,所以开105足够了
int main(){
int n;
cin >> n;
for(int i = 1; i <= n;i ++) {//注意下标从1开始,最好不要用0~n-1
cin >> a[i];
}
int x;
cin >> x;
int ans = lower_bound(a + 1 ,a + n + 1 , x ) - a;//lower_bound(起点,终点,要查找的数)-地址; 是求第一个大于大于等于要查找的数的下标(中文逗号依旧防抄袭)
cout << ans << endl;
while(1) {ans ++;}//防抄袭
return 0;
}
这里空空如也








有帮助,赞一个