diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-03-08 23:32:11 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-03-08 23:32:11 +0000 |
| commit | a0ea2c78c8ac2bb33fb79ab151f86b3beb143647 (patch) | |
| tree | 41cbffecd69bd6774b09657b5702f620154cf9cb /challenge-207/ulrich-rieke/cpp/ch-2.cpp | |
| parent | bc577f09f07be6abd72291c3e9a6642e4336d9c9 (diff) | |
| download | perlweeklychallenge-club-a0ea2c78c8ac2bb33fb79ab151f86b3beb143647.tar.gz perlweeklychallenge-club-a0ea2c78c8ac2bb33fb79ab151f86b3beb143647.tar.bz2 perlweeklychallenge-club-a0ea2c78c8ac2bb33fb79ab151f86b3beb143647.zip | |
- Added solutions by Avery Adams.
- Added solutions by Jaldhar H. Vyas.
- Added solutions by Mark Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by Peter Campbell Smith.
- Added solutions by W. Luis Mochan.
- Added solutions by Paulo Custodio.
- Added solutions by Cheok-Yin Fung.
- Added solutions by E. Choroba.
- Added solutions by Bob Lied.
- Added solutions by Robbie Hatley.
- Added solutions by Matthias Muth.
- Added solutions by Lubos Kolouch.
- Added solutions by Solathian.
- Added solutions by Duncan C. White.
- Added solutions by Kjetil Skotheim.
- Added solutions by Marton Polgar.
- Added solutions by David Ferrone.
- Added solutions by Mariano Spadaccini.
- Added solutions by Robert DiCicco.
- Added solutions by Ulrich Rieke.
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-207/ulrich-rieke/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-207/ulrich-rieke/cpp/ch-2.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-207/ulrich-rieke/cpp/ch-2.cpp b/challenge-207/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..cf957b6234 --- /dev/null +++ b/challenge-207/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,37 @@ +#include <vector> +#include <iostream> +#include <algorithm> +#include <string> + +std::vector<std::string> split( const std::string & startline , + const std::string & sep ) { + std::vector<std::string> separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Enter some integers, separated by a blank!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector<std::string> numberstrings( split( line , " " ) ) ; + std::vector<int> numbers ; + for ( auto & st : numberstrings ) + numbers.push_back( std::stoi( st ) ) ; + std::sort( numbers.begin( ) , numbers.end( ) , []( int a , int b ) { + return a > b ; } ) ; + std::vector<int> possible_h ; + for ( int i = 0 ; i < numbers.size( ) ; i++ ) { + if ( numbers[ i ] >= ( i + 1 ) ) + possible_h.push_back( i + 1 ) ; + } + std::cout << *max_element( possible_h.begin( ) , possible_h.end( ) ) << + std::endl ; + return 0 ; +} |
