题解:P8620 [蓝桥杯 2014 国 A] 排列序数

· · 题解

题意

给你一个字符串,求它的排列序数。

思路

全排列,直接用 next_permutation。

next_permutation 是全排列函数,每次计数器加一,当两个字符串相等就输出。

代码

#include<bits/stdc++.h>
using namespace std;
string s,a;
int ans;
int main(){
    cin>>s;
    a=s;
    sort(a.begin(),a.end());
    do{
        ans++;
        if(a==s){
            cout<<ans-1;
            return 0;
        }
    }while(next_permutation(a.begin(),a.end()));
}