Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
809 B
2
Indexable
Never
#include <iostream>
#include <algorithm>


int main()
{
    int numbers[100] = {};
    int maxID{}, i = {-1},id = {}, number{};

    int n{}, a{}, b{};
    int max{};

    do {
        std::cin >> number;
        if (number != 0) {
            i++;
            numbers[i] = number;
        }
        else {
            maxID = i;
        }
    } while (number);

    std::cin >> n;

    for (i = 0; i < n; i++) {
        std::cin >> a >> b;
        max = 0;
        a -= 1;
        b -= 1;
        if (a >= 0 && a  < maxID && b >= 0 && b < maxID) {
            for (id = std::min(a, b); id <= std::max(a, b); id++) {
                if (numbers[id] > max) {
                    max = numbers[id];
                }
            }
        }std::cout << max << "\n";
    }
}
Leave a Comment