aboutsummaryrefslogtreecommitdiff
path: root/challenge-215/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-215/ulrich-rieke/cpp/ch-1.cpp')
-rw-r--r--challenge-215/ulrich-rieke/cpp/ch-1.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-215/ulrich-rieke/cpp/ch-1.cpp b/challenge-215/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..5f874934ed
--- /dev/null
+++ b/challenge-215/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,28 @@
+#include <iostream>
+#include <string>
+#include <vector>
+#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 << "Please enter some words, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> allStrings ( split( line , " " ) ) ;
+ std::cout << std::count_if( allStrings.begin( ) , allStrings.end( ) ,
+ []( auto s ) { std::string c = s ; std::sort( c.begin( ) ,
+ c.end( ) ) ; return c != s ; } ) << std::endl ;
+ return 0 ;
+}