From a4a5c909234335cbf64764b067d3d0f23829f8fc Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Mon, 1 Apr 2024 16:12:40 +0200 Subject: Week 263 Task 1 by ash --- challenge-263/ash/cpp/ch-1.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 challenge-263/ash/cpp/ch-1.cpp (limited to 'challenge-263/ash/cpp/ch-1.cpp') diff --git a/challenge-263/ash/cpp/ch-1.cpp b/challenge-263/ash/cpp/ch-1.cpp new file mode 100644 index 0000000000..463f80aa43 --- /dev/null +++ b/challenge-263/ash/cpp/ch-1.cpp @@ -0,0 +1,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 +#include +#include +#include + +using namespace std; + +int main() { + vector> 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 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; + } +} -- cgit