blob: c04b8ffb581f2535957f4d7313aca50bae65cd1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 ;
}
|