aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/ash/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorAndrew Shitov <mail@andreyshitov.com>2024-04-01 16:12:40 +0200
committerAndrew Shitov <mail@andreyshitov.com>2024-04-01 16:12:40 +0200
commita4a5c909234335cbf64764b067d3d0f23829f8fc (patch)
tree5052f4346218693eb07c74c83c8a248030f843f4 /challenge-263/ash/cpp/ch-1.cpp
parentc9be1656455d23b019df372ed14a189133c588b1 (diff)
downloadperlweeklychallenge-club-a4a5c909234335cbf64764b067d3d0f23829f8fc.tar.gz
perlweeklychallenge-club-a4a5c909234335cbf64764b067d3d0f23829f8fc.tar.bz2
perlweeklychallenge-club-a4a5c909234335cbf64764b067d3d0f23829f8fc.zip
Week 263 Task 1 by ash
Diffstat (limited to 'challenge-263/ash/cpp/ch-1.cpp')
-rw-r--r--challenge-263/ash/cpp/ch-1.cpp48
1 files changed, 48 insertions, 0 deletions
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<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;
+ }
+}