跳到正文

题解

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

lkk1030约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年8月4日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 1 分钟
获赞
1
题目
P8620

版本

  1. v1当前

题意

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

思路

全排列,直接用 next_permutation。

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

代码

C++
#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()));
}
原文
存档评论1 条抓取于