From e35db9dbd7076795db94cf9d150dc14f879d9fa5 Mon Sep 17 00:00:00 2001 From: mustafaaydn Date: Mon, 8 Jan 2024 01:23:47 +0300 Subject: add solutions --- challenge-250/witawayar/cpp/ch-1.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-250/witawayar/cpp/ch-1.cpp (limited to 'challenge-250/witawayar/cpp/ch-1.cpp') 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 +#include +#include + +int fun(std::vector 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, 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"; +} -- cgit