low_bound用法(结构体)

发布时间 2023-05-17 16:49:45作者: 觉清风

输出第一个在a数组里大于等于m的数的下标

#include<bits/stdc++.h>
using namespace std;
struct nn{
    int num;
    bool operator < ( const nn  & x ) const {
        return num < x.num;
    } 
}a[10];
int main() {
    int n,m;
    cin>>n;
    for (int i = 1; i <= n; ++i) {
        cin>>a[i].num;
    }
    cin>>m;
    cout<<lower_bound( a + 1 , a + 1 + n , (nn){ m } ) - a;
}