aboutsummaryrefslogtreecommitdiff
path: root/challenge-238/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-238/ulrich-rieke/cpp/ch-1.cpp')
-rwxr-xr-xchallenge-238/ulrich-rieke/cpp/ch-1.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-238/ulrich-rieke/cpp/ch-1.cpp b/challenge-238/ulrich-rieke/cpp/ch-1.cpp
new file mode 100755
index 0000000000..255523fb1f
--- /dev/null
+++ b/challenge-238/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,38 @@
+#include <vector>
+#include <string>
+#include <iostream>
+
+std::vector<std::string> split( const std::string & startline ,
+ const std::string & sep ) {
+ std::vector<std::string> separated ;
+ std::string::size_type start { 0 } ;
+ std::string::size_type pos ;
+ do {
+ pos = startline.find_first_of( sep , start ) ;
+ separated.push_back( startline.substr(start , pos - start )) ;
+ start = pos + 1 ;
+ } while ( pos != std::string::npos ) ;
+ return separated ;
+}
+
+int main( ) {
+ std::cout << "Enter some integers, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> numberstrings( split( line , " " ) ) ;
+ std::vector<int> numbers ;
+ for ( auto s : numberstrings )
+ numbers.push_back( std::stoi( s ) ) ;
+ std::vector<int> result ;
+ int current_sum = 0 ;
+ int size = numbers.size( ) ;
+ for ( int i = 0 ; i < size ; i++ ) {
+ current_sum += numbers[ i ] ;
+ result.push_back( current_sum ) ;
+ }
+ std::cout << "( " ;
+ for ( int i : result )
+ std::cout << i << " " ;
+ std::cout << ")\n" ;
+ return 0 ;
+}