diff options
| author | Solathian <horvath6@gmail.com> | 2024-01-14 17:29:32 +0100 |
|---|---|---|
| committer | Solathian <horvath6@gmail.com> | 2024-01-14 17:29:32 +0100 |
| commit | 83179303806e75ac6aa4c786cefbb89ab6ddeaf7 (patch) | |
| tree | e11408dc893055aed5e1900d2fe35ed0ed6ea553 /challenge-250/witawayar/cpp/ch-2.cpp | |
| parent | ceb66bf893e3eadbf5e85843cd1495775f2d4d92 (diff) | |
| parent | dba8c691b150fd0086ac6f95e674d0302f437cac (diff) | |
| download | perlweeklychallenge-club-83179303806e75ac6aa4c786cefbb89ab6ddeaf7.tar.gz perlweeklychallenge-club-83179303806e75ac6aa4c786cefbb89ab6ddeaf7.tar.bz2 perlweeklychallenge-club-83179303806e75ac6aa4c786cefbb89ab6ddeaf7.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-250/witawayar/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-250/witawayar/cpp/ch-2.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-250/witawayar/cpp/ch-2.cpp b/challenge-250/witawayar/cpp/ch-2.cpp new file mode 100644 index 0000000000..290e1efc60 --- /dev/null +++ b/challenge-250/witawayar/cpp/ch-2.cpp @@ -0,0 +1,37 @@ +// g++ -Wall -Wextra -Wpedantic -std=c++17 cpp/ch-2.cpp +#include <iostream> +#include <sstream> +#include <vector> + +int fun(std::vector<std::string> alpha_num_strs) { + int max = -1; + for (const std::string& str : alpha_num_strs) { + int current = + str.find_first_not_of("0123456789") == std::string::npos + ? std::stoi(str) + : str.size(); + if (current > max) { + max = current; + } + } + return max; +} + +int main(void) { + std::vector<std::pair<std::vector<std::string>, int>> tests = { + {{"perl", "2", "000", "python", "r4ku"}, 6}, + {{"001", "1", "000", "0001"}, 1}, + {{"-12", "2"}, 3} + }; + + 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"; +} |
