aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/ash/cpp/ch-1.cpp
blob: 463f80aa436695910011e8df73a9450c739c8c4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Solution of Task 1 of The Weekly Challenge 263
// https://theweeklychallenge.org/blog/perl-weekly-challenge-263/

/*
    $ c++ -std=c++20 ch-1.cpp

    $ ./a.out 
    (1, 2)
    ()
    (4)
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main() {
    vector<vector<int>> tests = {
        {1, 5, 3, 2, 4, 2},
        {1, 2, 4, 3, 5},
        {5, 3, 2, 4, 2, 1}
    };

    int values[] = {2, 6, 4};

    for (int n = 0; n != tests.size(); n++) {
        auto vec = tests[n];
        auto value = values[n];

        sort(vec.begin(), vec.end());

        vector<int> result;
        for (int c = 0; c != vec.size(); c++) {
            if (vec[c] == value) result.push_back(c);
            if (vec[c] > value) break;
        }

        cout << "(";
        for (int c = 0; c != result.size(); c++) {
            cout << result[c];
            if (c < result.size() - 1) cout << ", ";
        }
        cout << ")" << endl;
    }
}