diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-02-10 20:39:47 +0000 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-02-10 20:39:47 +0000 |
| commit | e9d030e5fd8fa107797fac1489bca6ce2724d212 (patch) | |
| tree | 67b923088c999951deb2282143353932210d2cdf /challenge-308/ulrich-rieke/cpp/ch-2.cpp | |
| parent | a4ee687a84267a19ebcb6d9228ffe4f73927396b (diff) | |
| download | perlweeklychallenge-club-e9d030e5fd8fa107797fac1489bca6ce2724d212.tar.gz perlweeklychallenge-club-e9d030e5fd8fa107797fac1489bca6ce2724d212.tar.bz2 perlweeklychallenge-club-e9d030e5fd8fa107797fac1489bca6ce2724d212.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke.
- Added solutions by Mark Anderson.
- Added solutions by David Ferrone.
- Added solutions by Ali Moradi.
- Added solutions by Niels van Dijke.
- Added solutions by Peter Pentchev.
- Added solutions by E. Choroba.
- Added solutions by Peter Meszaros.
- Added solutions by Thomas Kohler.
- Added solutions by W. Luis Mochan.
- Added solutions by BarrOff.
Diffstat (limited to 'challenge-308/ulrich-rieke/cpp/ch-2.cpp')
| -rwxr-xr-x | challenge-308/ulrich-rieke/cpp/ch-2.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-308/ulrich-rieke/cpp/ch-2.cpp b/challenge-308/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..8a80cf6fc5 --- /dev/null +++ b/challenge-308/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,42 @@ +#include <iostream>
+#include <string>
+#include <sstream>
+#include <vector>
+
+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 ;
+}
+
+int main( ) {
+ std::cout << "Enter some numbers separated by whitespace!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ auto tokens { split( line , ' ' ) } ;
+ std::vector<int> encoded ;
+ for ( auto s : tokens )
+ encoded.push_back( std::stoi( s ) ) ;
+ std::cout << "Enter an initial integer!\n" ;
+ int initial ;
+ std::cin >> initial ;
+ std::vector<int> decoded ;
+ decoded.push_back( initial ) ;
+ //to find x in a xor x = b you can do a xor b since xor is its own
+ //inverse function!
+ for ( auto it = encoded.begin( ) ; it != encoded.end( ) ; ++it ) {
+ int last = decoded[decoded.size( ) - 1] ;
+ decoded.push_back( last ^ *it ) ;
+ }
+ std::cout << "( " ;
+ for ( int i : decoded ) {
+ std::cout << i << ' ' ;
+ }
+ std::cout << ")\n" ;
+ return 0 ;
+}
+
|
