From fecf841be0c99e005e24b74793ddfcf6a2f173c5 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 29 Sep 2020 22:30:37 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-080/ulrich-rieke/cpp/ch-1.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-080/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-080/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-080/ulrich-rieke/cpp/ch-1.cpp b/challenge-080/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..c4f51b0787 --- /dev/null +++ b/challenge-080/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +std::vector enterArray ( int limit ) { + std::vector numbers ; + int num ; + while ( numbers.size( ) < limit ) { + std::cin >> num ; + numbers.push_back( num ) ; + } + return numbers ; +} + +int main( ) { + std::cout << "How many numbers do you want to enter ?\n" ; + int num ; + std::cin >> num ; + std::cout << "Enter " << num << " numbers!\n" ; + std::vector numbers = enterArray( num ) ; + std::vector positives ; + for ( int i : numbers ) { + if ( i > 0 ) + positives.push_back( i ) ; + } + std::sort( positives.begin( ) , positives.end( ) ) ; + int current = 1 ; + auto found = std::find( positives.begin( ) , positives.end( ) , current ) ; + while ( found != positives.end( ) ) { + current++ ; + found = std::find( positives.begin( ) , positives.end( ) , current ) ; + } + std::cout << current << std::endl ; + return 0 ; +} -- cgit