aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-110/ulrich-rieke/awk/ch-2.awk18
-rw-r--r--challenge-110/ulrich-rieke/cpp/ch-1.cpp31
-rw-r--r--challenge-110/ulrich-rieke/cpp/ch-2.cpp61
3 files changed, 110 insertions, 0 deletions
diff --git a/challenge-110/ulrich-rieke/awk/ch-2.awk b/challenge-110/ulrich-rieke/awk/ch-2.awk
new file mode 100644
index 0000000000..fe97552ee1
--- /dev/null
+++ b/challenge-110/ulrich-rieke/awk/ch-2.awk
@@ -0,0 +1,18 @@
+BEGIN {
+ FS = ","
+}
+{
+ for (i = 1 ; i <= NF ; i = i + 1 ) {
+ if ( length( rows[ i ] ) == 0 ) {
+ rows[ i ] = $i
+ }
+ else {
+ rows[ i ] = rows[ i ] "," $i
+ }
+ }
+}
+END {
+ for (i = 1 ; i <= NF ; i = i + 1 ) {
+ print rows[i]
+ }
+}
diff --git a/challenge-110/ulrich-rieke/cpp/ch-1.cpp b/challenge-110/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..173a01075e
--- /dev/null
+++ b/challenge-110/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,31 @@
+#include <iostream>
+#include <string>
+#include <regex>
+#include <fstream>
+#include <vector>
+
+int main( int argc, char * argv[] ) {
+ if ( argc != 2 ) {
+ std::cerr << "Error! syntax challenge110 <inputfile>!\n" ;
+ return 1 ;
+ }
+ const char* const infile = argv[1] ;
+ std::ifstream myIn( infile , std::ios_base::in ) ;
+ if ( ! myIn.is_open( ) ) {
+ std::cerr << "error opening " << infile << '\n' ;
+ return 2 ;
+ }
+ std::vector<std::string> validLines ;
+ std::string regexstr(R"((\s*\+\d{2}|\(\d{2}\)|\d{4})\s\d{10})") ;
+ std::regex rgx( regexstr ) ;
+ while ( myIn ) {
+ std::string line ;
+ std::getline( myIn , line ) ;
+ if ( std::regex_search( line , rgx ) )
+ validLines.push_back( line ) ;
+ }
+ myIn.close( ) ;
+ for ( auto s : validLines )
+ std::cout << s << std::endl ;
+ return 0 ;
+}
diff --git a/challenge-110/ulrich-rieke/cpp/ch-2.cpp b/challenge-110/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..75f2e8cac2
--- /dev/null
+++ b/challenge-110/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,61 @@
+#include <iostream>
+#include <string>
+#include <fstream>
+#include <vector>
+
+std::vector<std::string> splitString( const std::string & word, char
+ separator ) {
+ std::vector<std::string> parts ;
+ std::string::size_type last_found = 0 ;
+ std::string::size_type pos = word.find_first_of( separator , last_found ) ;
+ while ( pos != std::string::npos ) {
+ parts.push_back( word.substr(last_found , pos - last_found)) ;
+ last_found = pos + 1 ;
+ pos = word.find_first_of( separator, last_found ) ;
+ }
+ parts.push_back( word.substr( last_found ) ) ;
+ return parts ;
+}
+
+int main( int argc, char * argv[] ) {
+ if ( argc != 2 ) {
+ std::cerr << "Error! syntax: challenge110_2 <source file>!\n" ;
+ return 1 ;
+ }
+ const char * const infile = argv[ 1 ] ;
+ std::ifstream myIn( infile , std::ios_base::in ) ;
+ if ( ! myIn.is_open( )) {
+ std::cerr << "cannot open file " << argv[1] << "!\n" ;
+ return 2 ;
+ }
+ std::vector<std::string> partsInLine ;
+ std::vector<std::string> allWords ;
+ std::string line ;
+ int fields = 0 ;
+ while ( myIn ) {
+ std::getline( myIn , line ) ;
+ partsInLine = splitString( line , ',' ) ;
+ if ( ! line.empty( ) ) {
+ fields = partsInLine.size( ) ;
+ for ( auto s : partsInLine )
+ allWords.push_back( s ) ;
+ }
+ }
+ myIn.close( ) ;
+ std::vector<std::string> myOut ;
+ for ( int start = 0 ; start < fields ; start++ ) {
+ myOut.clear( ) ;
+ myOut.push_back( allWords[ start ] ) ;
+ for ( int jumpTo = start + fields ; jumpTo < allWords.size( ) ; jumpTo += fields )
+ myOut.push_back( allWords[ jumpTo ] ) ;
+ int count = 0 ;
+ for ( auto s : myOut ) {
+ std::cout << s ;
+ if ( count < myOut.size( ) - 1 )
+ std::cout << ", " ;
+ count++ ;
+ }
+ std::cout << std::endl ;
+ }
+ return 0 ;
+}