next_permutation(start,end)

一道水题,简单的next_permutation用法,相同的还有prev_permutation 包含在头文件<algorithm>中

字符串 acab 含有两个a ,一个b ,一个c ,和acab 含的字母和每个字母的个数都相等的字符串还有:aacb,baca等,因为他们也是含有两个a ,一个b ,一个c。 所有满足这个性质的字符串按字典顺序排列后,acab 是第5个,我们就说acab的序号是5。 再如:ba的序号是2,aa 的序号是1。 编程求出给定字符串 S(长度<=100)的序号 P(保证<=30000) 注意:字符串只含小写字母。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 #include <map>
 5 #include <set>
 6 #include <algorithm>
 7 #include <fstream>
 8 #include <cstdio>
 9 #include <cmath>
10 #include <stack>
11 #include <queue>
12 #define lson l,m,rt<<1
13 #define rson m+1,r,rt<<1|1
14 using namespace std;
15 const double Pi=3.14159265358979323846;
16 typedef long long ll;
17 const int MAXN=200+5;
18 const int dx[4]={0,0,1,-1};
19 const int dy[4]={1,-1,0,0};
20 const int INF = 0x3f3f3f3f;
21 const int NINF = 0xc0c0c0c0;
22 const ll mod=1e9+7;
23 int main()
24 {
25     string str;cin>>str;
26     string str0=str;
27     sort(str0.begin(),str0.end());
28     int cnt=1;
29     
30     while(str0!=str)
31     {
32         cnt++;
33         next_permutation(str0.begin(),str0.end());
34     }
35     cout <<cnt<<endl;
36     return 0;
37 }

 

转载于:https://www.cnblogs.com/Msmw/p/10544847.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值