First occurrence

Write an efficient function

    int first_occurrence(double x, const vector<double>& v);

that returns the position of the first occurrence of xx in the vector vv. If xx does not belong to vv, return a -1.

Precondition

The vector vv is sorted in nondecreasing order.

Observation

You only need to submit the required procedure; your main program will be ignored.

Problem information

Author: Salvador Roura

Generation: 2026-03-10T18:56:21.017Z

© Jutge.org, 2006–2026.
https://jutge.org