logo

Crowdly

#define main1 main /** Question C1 What is output of the program? */ // //bi...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

#define main1 main

/** Question C1

What is output of the program?

*/

//

//binary_search, lower_bound, upper_bound 

#include <iostream>

#include <vector>

#include <algorithm>

int main1() {

    std::vector<int> v = {6, 7, 4, -5, 3, -2, 6, 8, 8, 0, -2, 1};

    std::ranges::sort(v);

    bool found = std::ranges::binary_search(v, -5);

    auto itL = std::ranges::lower_bound(v, -4);

    auto itU = std::ranges::upper_bound(v, -2);

    int posL = static_cast<int>(itL - v.begin());

    int posU = static_cast<int>(itU - v.begin());

    int count = posU - posL;

    int first = (itL == v.end()) ? 999 : *itL;

    int last  = (itU == v.begin()) ? 999 : *(itU - 1);

    std::cout << found << "|" << posL << "|" << posU << "|" << count << "|" << first << "|" << last;

    return 0;

}

More questions like this

Want instant access to all verified answers on emokymai.vu.lt?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!