For this Question: Given a string, Calculate its rank among all its lexicographically sorted permutations.First line of the input contains a string S.

<b>Constraints</b>
1 ≤ |S| ≤ 8Print the Rank of that string.Sample Input
CBA

Sample Output
6

Explanation
The rank of string CBA in the lexicographically sorted permutations [ABC, ACB, BAC, BCA, CAB, CBA] is 6., I have written this Solution Code: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
// Function to find the lexicographic rank of a string using
// `std::next_permutation`
int findLexicographicRank(string key)
{
    string str = key;
    int rank = 1;        // rank starts from 1
 
    // sort the string in ascending order
    sort(str.begin(), str.end());
 
    while (1)
    {
        // if the current permutation is equal to the key, return its rank
        if (key == str) {
            return rank;
        }
 
        // find next lexicographically ordered permutation
        if (!next_permutation(str.begin(), str.end())) {
            break;
        }
        rank++;
    }
return rank ;
}
 
int main()
{
    string key;
    cin>>key;
 
    cout << findLexicographicRank(key);
 
    return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?