aboutsummaryrefslogtreecommitdiff
path: root/challenge-228/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-08-01 00:30:26 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-08-01 00:30:26 +0100
commitb7c6ba230d95ffad246f0f9874e82cbd95e12f56 (patch)
treec4ba4a2568676aba47a13dba8dcd5ea206366461 /challenge-228/ulrich-rieke/cpp/ch-1.cpp
parentb7b0353c40a650fce3847d239aa83c2eb67086ac (diff)
downloadperlweeklychallenge-club-b7c6ba230d95ffad246f0f9874e82cbd95e12f56.tar.gz
perlweeklychallenge-club-b7c6ba230d95ffad246f0f9874e82cbd95e12f56.tar.bz2
perlweeklychallenge-club-b7c6ba230d95ffad246f0f9874e82cbd95e12f56.zip
- Added solutions by Niels van Dijke.
- Added solutions by Ulrich Rieke. - Added solutions by Robert DiCicco. - Added solutions by Laurent Rosenfeld. - Added solutions by Peter Meszaros. - Added solutions by Mark Anderson. - Added solutions by Lubos Kolouch. - Added solutions by Ali Moradi. - Added solutions by Dave Jacoby. - Added solutions by Peter Campbell Smith. - Added solutions by W. Luis Mochan. - Added solutions by Steven Wilson. - Added solutions by Thomas Kohler. - Added solutions by E. Choroba. - Added solutions by Bob Lied.
Diffstat (limited to 'challenge-228/ulrich-rieke/cpp/ch-1.cpp')
-rwxr-xr-xchallenge-228/ulrich-rieke/cpp/ch-1.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-228/ulrich-rieke/cpp/ch-1.cpp b/challenge-228/ulrich-rieke/cpp/ch-1.cpp
new file mode 100755
index 0000000000..106d4ee20f
--- /dev/null
+++ b/challenge-228/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,35 @@
+#include <iostream>
+#include <vector>
+#include <string>
+#include <numeric>
+#include <algorithm>
+
+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> uniques ;
+ for ( int i : numbers ) {
+ if ( std::count( numbers.begin( ) , numbers.end( ) , i ) == 1 )
+ uniques.push_back( i ) ;
+ }
+ std::cout << std::accumulate( uniques.begin( ) , uniques.end( ) , 0 ) << std::endl ;
+ return 0 ;
+}