Lexicographic rank of a string
I have a couple of issues with the main function.

First, system("pause") may work for windows but won't elsewhere. You should dump it.

Second, Too many returns at the end.

Third, The hardcoded input makes it kinda hard to test (and doesn't look good). Just read the first parameter from the command line or read in from standard in. Here is an easy way to do so:

int main(int argc, char** argv) {
    string str;
    if(argc &gt;= 2){
        str = argv[1];
    } else {
        cout &lt;&lt; "Enter a string: ";
        cin &gt;&gt; str;
    }
    cout &lt;&lt; rank(str) &lt;&lt; endl;
    return 0;
}