First occurrence

Write an efficient function

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

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

Precondition

The vector @v@ 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-01-25T12:01:18.170Z

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