aboutsummaryrefslogtreecommitdiff
path: root/challenge-080/ash/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-30 13:49:48 +0100
committerGitHub <noreply@github.com>2020-09-30 13:49:48 +0100
commitc459362b55a9a174f13dc1fd29c9c651ed738e6d (patch)
tree3ee4b6918c0fa5de3cd206e5afbc48560a7c740d /challenge-080/ash/cpp/ch-1.cpp
parent96f3ffb9600ca187d982c537939c096b084fe409 (diff)
parentf3610ba736a27f0c3373bf65b424d3cbba85d2df (diff)
downloadperlweeklychallenge-club-c459362b55a9a174f13dc1fd29c9c651ed738e6d.tar.gz
perlweeklychallenge-club-c459362b55a9a174f13dc1fd29c9c651ed738e6d.tar.bz2
perlweeklychallenge-club-c459362b55a9a174f13dc1fd29c9c651ed738e6d.zip
Merge pull request #2416 from ash/master
Solutions 080-1 in C++ and Raku
Diffstat (limited to 'challenge-080/ash/cpp/ch-1.cpp')
-rw-r--r--challenge-080/ash/cpp/ch-1.cpp38
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..278833993b
--- /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;
+}