aboutsummaryrefslogtreecommitdiff
path: root/challenge-250/witawayar/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-07 23:15:12 +0000
committerGitHub <noreply@github.com>2024-01-07 23:15:12 +0000
commit2eec7728a3c50e30f205fda0ea1370c426af800d (patch)
tree3239d9bd297024a9d6b11d4e480d63f87e03696b /challenge-250/witawayar/cpp/ch-1.cpp
parentd32628dbd0b5623fc6565f3c68dfd1507e2aaaa8 (diff)
parente35db9dbd7076795db94cf9d150dc14f879d9fa5 (diff)
downloadperlweeklychallenge-club-2eec7728a3c50e30f205fda0ea1370c426af800d.tar.gz
perlweeklychallenge-club-2eec7728a3c50e30f205fda0ea1370c426af800d.tar.bz2
perlweeklychallenge-club-2eec7728a3c50e30f205fda0ea1370c426af800d.zip
Merge pull request #9360 from mustafaaydn/challenge_250
Solutions for the 250th challenge
Diffstat (limited to 'challenge-250/witawayar/cpp/ch-1.cpp')
-rw-r--r--challenge-250/witawayar/cpp/ch-1.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-250/witawayar/cpp/ch-1.cpp b/challenge-250/witawayar/cpp/ch-1.cpp
new file mode 100644
index 0000000000..0f665202a8
--- /dev/null
+++ b/challenge-250/witawayar/cpp/ch-1.cpp
@@ -0,0 +1,31 @@
+// g++ -Wall -Wextra -Wpedantic -std=c++17 cpp/ch-1.cpp
+#include <iostream>
+#include <sstream>
+#include <vector>
+
+int fun(std::vector<int> ints) {
+ for (size_t i = 0; i < ints.size(); ++i) {
+ if ((int) i % 10 == ints[i])
+ return i;
+ }
+ return -1;
+}
+
+int main(void) {
+ std::vector<std::pair<std::vector<int>, int>> tests = {
+ {{0, 1, 2}, 0},
+ {{4, 3, 2, 1}, 2},
+ {{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, -1}
+ };
+
+ for (const auto& [input, expected_output] : tests) {
+ int got = fun(input);
+ if (got != expected_output) {
+ std::stringstream error_msg;
+ error_msg << "Expected " << expected_output << ", got " << got;
+ throw std::runtime_error(error_msg.str());
+ }
+ }
+
+ std::cout << "done-testing, success\n";
+}