diff options
| author | rir <rirans@comcast.net> | 2024-03-16 20:07:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-16 20:07:25 -0400 |
| commit | ff5e8ece15a2384fbfb530710f10aa485017d4a5 (patch) | |
| tree | 6fe268d9ceb2b25a2951ea984c077450feb2efae /challenge-260/ulrich-rieke/cpp/ch-2.cpp | |
| parent | 60f1003122fbada697317d943c238593f86db579 (diff) | |
| parent | 62e7fc3bb85a74125663f4fbd0a5911f6f30c81f (diff) | |
| download | perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.tar.gz perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.tar.bz2 perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.zip | |
Merge branch 'manwar:master' into work
Diffstat (limited to 'challenge-260/ulrich-rieke/cpp/ch-2.cpp')
| -rwxr-xr-x | challenge-260/ulrich-rieke/cpp/ch-2.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-260/ulrich-rieke/cpp/ch-2.cpp b/challenge-260/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..c04b8ffb58 --- /dev/null +++ b/challenge-260/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,23 @@ +#include <iostream>
+#include <algorithm>
+#include <string>
+#include <iterator>
+#include <vector>
+
+int main( ) {
+ std::cout << "Enter a word, preferably in capital letters only!\n" ;
+ std::string word ;
+ std::getline( std::cin , word ) ;
+ std::string entered { word } ;
+ std::vector<std::string> permus ;
+ std::sort( word.begin( ) , word.end( ) ) ;
+ do {
+ permus.push_back( word ) ;
+ } while ( std::next_permutation( word.begin( ) , word.end( ) )) ;
+ std::sort( permus.begin( ) , permus.end( ) ) ;
+ auto found = std::find( permus.begin( ) , permus.end( ) , entered ) ;
+ std::cout << (static_cast<int>(std::distance( permus.begin( ) , found)))
+ + 1 ;
+ std::cout << '\n' ;
+ return 0 ;
+}
|
