diff options
Diffstat (limited to 'challenge-343/ulrich-rieke/cpp/ch-1.cpp')
| -rwxr-xr-x | challenge-343/ulrich-rieke/cpp/ch-1.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-343/ulrich-rieke/cpp/ch-1.cpp b/challenge-343/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..09bb86a185 --- /dev/null +++ b/challenge-343/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,29 @@ +#include <iostream>
+#include <vector>
+#include <sstream>
+#include <string>
+#include <algorithm>
+#include <cstdlib>
+
+std::vector<std::string> split( const std::string & text , const 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 ;
+}
+
+//we want to find the minimum absolute value!
+int main( ) {
+ std::cout << "Enter some integers separated by whitespace!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ auto tokens { split( line , ' ' ) } ;
+ std::vector<int> differences ;
+ for ( auto s : tokens )
+ differences.push_back( std::abs(std::stoi( s ) )) ;
+ std::cout << *std::min_element( differences.begin( ) , differences.end( ) ) <<
+ '\n' ;
+ return 0 ;
+}
|
