diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2022-11-20 14:22:01 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2022-11-20 14:22:01 -0500 |
| commit | dd682dfee966fe63cbfbbbf6a9cb903b1d831416 (patch) | |
| tree | a71619e10c8dcd29fc13a08beb1325f4a7bc5a84 /challenge-191/ulrich-rieke/cpp/ch-1.cpp | |
| parent | d6d01468fd7a5647b9ba96ebf7a0157ff79f3352 (diff) | |
| parent | bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (diff) | |
| download | perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.gz perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.bz2 perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-191/ulrich-rieke/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-191/ulrich-rieke/cpp/ch-1.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-191/ulrich-rieke/cpp/ch-1.cpp b/challenge-191/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..35a1da15bf --- /dev/null +++ b/challenge-191/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,33 @@ +#include <iostream> +#include <vector> +#include <string> +#include <algorithm> + +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 << "Please enter a number of integers, separated by blanks!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector<std::string> numberstrings( split( line , " " )) ; + std::vector<int> numbers ; + for ( auto & s : numberstrings ) + numbers.push_back( std::stoi( s )) ; + int maximum = *std::max_element( numbers.begin( ) , numbers.end( )) ; + if ( std::any_of( numbers.begin( ) , numbers.end( ) , [maximum]( const int n ) { + return ( n != maximum && maximum < 2 * n ) ; })) + std::cout << -1 << std::endl ; + else + std::cout << 1 << std::endl ; + return 0 ; +} |
