From c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 4 Oct 2022 20:17:51 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-185/ulrich-rieke/cpp/ch-1.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-185/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-185/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-185/ulrich-rieke/cpp/ch-1.cpp b/challenge-185/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..244b482591 --- /dev/null +++ b/challenge-185/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,20 @@ +#include +#include + +int main( ) { + std::cout << "Please enter a MAC address in the form hhhh.hhhh.hhhh!\n" ; + std::string address ; + std::getline( std::cin , address ) ; + int pos = 0 ; + std::string output ; + while ( pos < address.length( ) - 2 ) { + output.append( address.substr( pos , 2 )) ; + output.append( ":" ) ; + pos += 2 ; + if ( address.substr( pos , 1 ) == "." ) + pos++ ; + } + //take the output substr because we want to leave out the final ':' + std::cout << output.substr(0 , output.length( ) - 1 ) << std::endl ; + return 0 ; +} -- cgit