Skip to content

Instantly share code, notes, and snippets.

@andrei14vl
Created January 5, 2016 20:01
Show Gist options
  • Save andrei14vl/a7098a04f11d3073c404 to your computer and use it in GitHub Desktop.
Save andrei14vl/a7098a04f11d3073c404 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
using namespace std;
struct MyType {
int val;
int extra;
} arr[100];
bool cmp(int val, MyType my_object) {
if (my_object.val < val)
return false;
return true;
}
int main() {
int n = 10;
for (int i = 1; i <= 10; ++i) {
arr[i].val = i * 2;
}
int val;
cin >> val;
cout << upper_bound(arr + 1, arr + n + 1, val, cmp) - arr;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment