aboutsummaryrefslogtreecommitdiff
path: root/challenge-343/ulrich-rieke/cpp/ch-1.cpp
blob: 09bb86a1853f370dd66ac15579bec6468480da43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 ;
}