跳到正文

个人记录

low_bound用法(结构体)

Trump_约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年2月2日
收录
2026年3月16日
更新
2026年11月9日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#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;
}

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

原文