blob: 8d869cf12749fc3b58d4ada5a65d8f1c47a010e8 (
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
30
31
32
33
34
35
36
37
38
39
|
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdlib>
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 whitespace!\n" ;
std::string line ;
std::getline( std::cin , line ) ;
auto firsttokens { split( line , ' ' ) } ;
std::cout << "Enter some more integers separated by whitespace!\n" ;
std::getline( std::cin , line ) ;
auto secondtokens { split( line , ' ' ) } ;
std::vector<int> firstnums , secondnums , differences ;
for ( auto s : firsttokens )
firstnums.push_back( std::stoi( s ) ) ;
for ( auto s : secondtokens )
secondnums.push_back( std::stoi( s ) ) ;
for ( auto fit = firstnums.begin( ) ; fit != firstnums.end( ) ; ++fit ) {
for ( auto sit = secondnums.begin( ) ; sit != secondnums.end( ) ; ++sit ) {
differences.push_back( std::abs( *fit - *sit ) ) ;
}
}
std::cout << *std::max_element( differences.begin( ) , differences.end( ) ) <<
'\n' ;
return 0 ;
}
|