题意:将给出的序列输出按字典序的下一个序列,如果没有输出NO

题解:调用库函数中的next_permutation(s, s + n),直接将原来的序列变为下一个排列, n是序列的长度。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N  = 55;

int main() {
	char s[N];
	while (scanf("%s", s) && s[0] != '#') {
		if (next_permutation(s, s + strlen(s))) {
			printf("%s\n", s);
		}
		else
			printf("No Successor\n");
	}
}