aboutsummaryrefslogtreecommitdiff
path: root/challenge-320/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-320/ulrich-rieke/cpp/ch-1.cpp')
-rwxr-xr-xchallenge-320/ulrich-rieke/cpp/ch-1.cpp36
1 files changed, 36 insertions, 0 deletions
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 <vector>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <cstdlib>
+#include <algorithm>
+
+std::vector<std::string> split( const std::string & text , char delimiter ) {
+ std::vector<std::string> 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<int> 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 ;
+}