POJ 1146 ID Codes

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;
}


你可能感兴趣的:(POJ 1146 ID Codes)