From b91a4623cd4c2b51f779f59b53310a0bd745f03f Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 18 Mar 2024 17:15:14 +0000 Subject: - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. - Added solutions by Andrew Shitov. - Added solutions by Peter Meszaros. - Added solutions by Feng Chang. - Added solutions by Mark Anderson. - Added solutions by Peter Campbell Smith. - Added solutions by E. Choroba. - Added solutions by W. Luis Mochan. - Added solutions by David Ferrone. --- challenge-261/ulrich-rieke/cpp/ch-2.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 challenge-261/ulrich-rieke/cpp/ch-2.cpp (limited to 'challenge-261/ulrich-rieke/cpp/ch-2.cpp') diff --git a/challenge-261/ulrich-rieke/cpp/ch-2.cpp b/challenge-261/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..e5a956a286 --- /dev/null +++ b/challenge-261/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +std::vector split( const std::string & startline , + const std::string & sep ) { + std::vector 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 blanks!\n" ; + std::string numberline ; + std::getline( std::cin , numberline ) ; + std::vector innumbers { split( numberline , " " ) } ; + std::vector numbers ; + for ( auto w : innumbers ) + numbers.push_back( std::stoi( w ) ) ; + std::cout << "Enter a start number!\n" ; + int start ; + std::cin >> start ; + while ( std::find( numbers.begin( ) , numbers.end( ) , start ) != + numbers.end( ) ) + start *= 2 ; + std::cout << start << '\n' ; + return 0 ; +} -- cgit