aboutsummaryrefslogtreecommitdiff
path: root/challenge-321/ulrich-rieke/cpp/ch-2.cpp
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-05-13 13:30:54 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-05-13 13:30:54 +0100
commita799bc96049a853dae3a0b8bf14c4eb581a4a4ba (patch)
tree129fea9bbf713c223e3ad23f6b43ef3a17397340 /challenge-321/ulrich-rieke/cpp/ch-2.cpp
parent152c0ffaaa3df8dfa2a5dbff97971ec378999b0a (diff)
downloadperlweeklychallenge-club-a799bc96049a853dae3a0b8bf14c4eb581a4a4ba.tar.gz
perlweeklychallenge-club-a799bc96049a853dae3a0b8bf14c4eb581a4a4ba.tar.bz2
perlweeklychallenge-club-a799bc96049a853dae3a0b8bf14c4eb581a4a4ba.zip
- 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.
Diffstat (limited to 'challenge-321/ulrich-rieke/cpp/ch-2.cpp')
-rwxr-xr-xchallenge-321/ulrich-rieke/cpp/ch-2.cpp32
1 files changed, 32 insertions, 0 deletions
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 <iostream>
+#include <string>
+#include <vector>
+#include <sstream>
+
+std::vector<std::string> split( const std::string & text , char delimiter ) {
+ std::vector<std::string> 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 ;
+}