From 642b9c4df5cd463cbb354cbcfbefecb97cc97fa5 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 27 Sep 2022 09:48:40 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-184/ulrich-rieke/cpp/ch-1.cpp | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 challenge-184/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-184/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-184/ulrich-rieke/cpp/ch-1.cpp b/challenge-184/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..92fe5d702c --- /dev/null +++ b/challenge-184/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +int main( ) { + std::vector input ; + std::cout << "Please enter a string, starting with 2 digits and then 4 letters!\n" ; + std::cout << "enter to end!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + while ( !line.empty( ) ) { + input.push_back( line ) ; + std::getline( std::cin , line ) ; + } + int count = 0 ; + std::vector output ; + for ( auto it = input.begin( ) ; it != input.end( ) ; ++it ) { + std::string newWord ; + if ( count < 10 ) { + newWord = "0" + std::to_string( count ) + it->substr( 2 ) ; + } + if ( count > 9 ) { + newWord = std::to_string( count ) + it->substr( 2 ) ; + } + output.push_back( newWord ) ; + count++ ; + } + std::cout << '(' ; + for ( const auto & w : output ) { + std::cout << w ; + if ( w != output.back( ) ) + std::cout << ", " ; + } + std::cout << ')' << std::endl ; + return 0 ; +} -- cgit