From 6c6480baed8abb849ed2d2ffa29f5e8710b64268 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 2 May 2023 19:35:38 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-215/ulrich-rieke/cpp/ch-1.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 challenge-215/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-215/ulrich-rieke/cpp/ch-1.cpp') 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 +#include +#include +#include + +std::vector split( const std::string & startline , + const std::string & sep ) { + std::vector 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 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 ; +} -- cgit