diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-09-27 09:48:40 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-09-27 09:48:40 +0100 |
| commit | 642b9c4df5cd463cbb354cbcfbefecb97cc97fa5 (patch) | |
| tree | f389ae9815c2884a8eb405663d23554f5fd6c30e /challenge-184/ulrich-rieke/cpp/ch-1.cpp | |
| parent | d2dbff2eae0647c51ba7795ed75b7978b1896177 (diff) | |
| download | perlweeklychallenge-club-642b9c4df5cd463cbb354cbcfbefecb97cc97fa5.tar.gz perlweeklychallenge-club-642b9c4df5cd463cbb354cbcfbefecb97cc97fa5.tar.bz2 perlweeklychallenge-club-642b9c4df5cd463cbb354cbcfbefecb97cc97fa5.zip | |
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-184/ulrich-rieke/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-184/ulrich-rieke/cpp/ch-1.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
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 <vector> +#include <iostream> +#include <string> + +int main( ) { + std::vector<std::string> input ; + std::cout << "Please enter a string, starting with 2 digits and then 4 letters!\n" ; + std::cout << "enter <return> 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<std::string> 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 ; +} |
