diff options
Diffstat (limited to 'challenge-080/ulrich-rieke/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-080/ulrich-rieke/cpp/ch-1.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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 <vector> +#include <iostream> +#include <algorithm> + +std::vector<int> enterArray ( int limit ) { + std::vector<int> 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<int> numbers = enterArray( num ) ; + std::vector<int> 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 ; +} |
