blob: 2894348b288b3e0c0cf3452e184c90705963a9bf (
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 <string>
#include <sstream>
#include <vector>
#include <iostream>
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 tokens { split( line , ' ' ) } ;
std::vector<int> numbers ;
for ( auto s : tokens )
numbers.push_back( std::stoi( s ) ) ;
std::vector<int> afterDoubling ;
for ( auto it = numbers.begin( ) ; it != numbers.end( ) ; ++it ) {
if ( *it == 0 ) {
afterDoubling.push_back( 0 ) ;
afterDoubling.push_back( 0 ) ;
}
else
afterDoubling.push_back( *it ) ;
}
std::cout << "( " ;
for ( int i = 0 ; i < numbers.size( ) ; i++ ) {
std::cout << afterDoubling[i] << ' ' ;
}
std::cout << ")\n" ;
return 0 ;
}
|