diff options
Diffstat (limited to 'challenge-080/ash/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-080/ash/cpp/ch-1.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-080/ash/cpp/ch-1.cpp b/challenge-080/ash/cpp/ch-1.cpp new file mode 100644 index 0000000000..e006218f32 --- /dev/null +++ b/challenge-080/ash/cpp/ch-1.cpp @@ -0,0 +1,38 @@ +/* + Task 1 from + https://perlweeklychallenge.org/blog/perl-weekly-challenge-080/ +*/ + +#include <iostream> +#include <vector> +#include <map> + +using namespace std; + +int missing_n(vector<int> n) { + map<int, bool> v; + + int max = n[0]; + for (auto x : n) { + v[x] = true; + if (x > max) max = x; + } + + for (auto c = 1; c <= max ; c++) { + if (!v[c]) { + return c; + break; + } + } + + return max + 1; +} + +int main() { + cout << (missing_n(vector<int> {5, 2, -2, 0}) == 1) << endl; + cout << (missing_n(vector<int> {1, 8, -1}) == 2) << endl; + cout << (missing_n(vector<int> {5, 2, -2, 0}) == 1) << endl; + + cout << (missing_n(vector<int> {5, 2, 3, 1, -2, 0}) == 4) << endl; + cout << (missing_n(vector<int> {5, 2, 3, 1, 4, -2, 0}) == 6) << endl; +} |
