next_permutation解之。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 60;
char str[MAXN];
void solve()
{
int len = strlen(str);
bool f = next_permutation(str, str+len);
if(!f)
{
printf("No Successor\n");
}
else printf("%s\n", str);
}
bool read_case()
{
scanf("%s", str);
if(str[0] == '#') return 0;
return 1;
}
int main()
{
while(read_case())
{
solve();
}
return 0;
}
本文介绍了一个使用C++标准库函数next_permutation实现寻找字典序下一个排列的程序实例。该程序通过读取字符串输入并利用next_permutation函数生成其字典序下一个可能的排列,若不存在则输出提示信息。
1201

被折叠的 条评论
为什么被折叠?



