现在的位置: 首页 > 综合 > 正文

UVA 146 ID Codes(排列)

2018年03月17日 ⁄ 综合 ⁄ 共 326字 ⁄ 字号 评论关闭

题意:给你一个字符串,求它的下一个排列,按字典序。

思路:水题,用到一下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;
}

抱歉!评论已关闭.