From a799bc96049a853dae3a0b8bf14c4eb581a4a4ba Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 13 May 2025 13:30:54 +0100 Subject: - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. - Added solutions by Mark Anderson. - Added solutions by Feng Chang. - Added solutions by E. Choroba. - Added solutions by Niels van Dijke. - Added solutions by Andreas Mahnke. - Added solutions by Luca Ferrari. - Added solutions by Andrew Shitov. - Added solutions by Ali Moradi. - Added solutions by W. Luis Mochan. - Added solutions by David Ferrone. - Added solutions by Conor Hoekstra. - Added solutions by Peter Meszaros. - Added solutions by Robert Ransbottom. - Added solutions by Peter Campbell Smith. - Added solutions by Robbie Hatley. --- challenge-321/ulrich-rieke/cpp/ch-2.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 challenge-321/ulrich-rieke/cpp/ch-2.cpp (limited to 'challenge-321/ulrich-rieke/cpp/ch-2.cpp') diff --git a/challenge-321/ulrich-rieke/cpp/ch-2.cpp b/challenge-321/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..caf736cbfb --- /dev/null +++ b/challenge-321/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +std::vector split( const std::string & text , char delimiter ) { + std::vector tokens ; + std::istringstream istr { text } ; + std::string word ; + while ( std::getline( istr , word , delimiter ) ) + tokens.push_back( word ) ; + return tokens ; +} + +std::string reduceStr( std::string word ) { + auto it = word.find( "#" ) ; + while ( it != std::string::npos ) { + word = word.erase( --it , 2 ) ; + it = word.find( "#" ) ; + } + return word ; +} + +int main( ) { + std::cout << "Enter 2 words witz zero or more #!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + auto tokens { split( line , ' ' ) } ; + std::cout << std::boolalpha << ( reduceStr( tokens[0] ) == + reduceStr( tokens[1] ) ) << '\n' ; + return 0 ; +} -- cgit