From 7d67833e2e7de682d2d418145812d575218e0fa9 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 6 May 2025 15:45:31 +0100 Subject: - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. - Added solutions by David Ferrone. - Added solutions by E. Choroba. - Added solutions by Mark Anderson. - Added solutions by Jaldhar H. Vyas. - Added solutions by Ali Moradi. - Added solutions by Feng Chang. - Added solutions by Vinod Kumar K. - Added solutions by Peter Campbell Smith. - Added solutions by Ali Moradi. - Added solutions by Feng Chang. - Added solutions by Conor Hoekstra. - Added solutions by Bob Lied. - Added solutions by Athanasius. - Added solutions by W. Luis Mochan. - Added solutions by Andrew Shitov. - Added solutions by PokGoPun. - Added solutions by Roger Bell_West. --- challenge-320/ulrich-rieke/cpp/ch-1.cpp | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 challenge-320/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-320/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-320/ulrich-rieke/cpp/ch-1.cpp b/challenge-320/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..158bba2cb8 --- /dev/null +++ b/challenge-320/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +std::vector split( const std::string & text , char delimiter ) { + std::vector tokens ; + std::istringstream istr { text } ; + std::string word ; + while ( std::getline( istr , word , delimiter ) ) + tokens.push_back( word ) ; + return tokens ; +} + +int main( ) { + std::cout << "Enter some integers separated by blanks!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + auto tokens { split( line , ' ' ) } ; + std::vector numbers ; + for ( auto s : tokens ) + numbers.push_back( std::stoi( s ) ) ; + int positives = std::count_if( numbers.begin( ) , numbers.end( ) , [](int i) { + return i > 0 ; } ) ; + int negatives = std::count_if( numbers.begin( ) , numbers.end( ) , [](int i) { + return i < 0 ; } ) ; + if ( positives != 0 || negatives != 0 ) { + std::cout << std::max( positives , negatives ) << '\n' ; + } + else { + std::cout << 0 << '\n' ; + } + return 0 ; +} -- cgit