diff options
Diffstat (limited to 'challenge-321/ulrich-rieke/cpp/ch-2.cpp')
| -rwxr-xr-x | challenge-321/ulrich-rieke/cpp/ch-2.cpp | 32 |
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 ;
+}
|
