logo

Crowdly

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

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

#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 = {4, 6, 7, -5, 7, 5, -5, 7, 5, 5, -3, 9};

    std::ranges::sort(v);

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

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

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

    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;

}

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на emokymai.vu.lt?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!