题意:给你一个字符串,求它的下一个排列,按字典序。
思路:水题,用到一下next_permutation 求下一个排列函数。
//0 KB 18 ms
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define M 55
using namespace std;
int main ()
{
char str[M];
while (~scanf ("%s",str))
{
if (str[0] == '#')
break;
int len = strlen(str);
if (next_permutation(str,str+len))
printf ("%s\n",str);
else
printf ("No Successor\n");
}
return 0;
}
本文介绍了一个简单的算法问题,即寻找给定字符串的下一个字典序排列。通过使用C++标准库中的next_permutation函数实现解决方案,并附带了完整的代码示例。

1298

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



