22778_TheNextPermutation

2022-5-16 18:22| 发布者: Hocassian| 查看: 26| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506949028900-Problem List-采集的数据-后羿采集器.html

Pro.ID

22778

Title

The Next Permutation

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22778

AC

23

Submit

42

Ratio

54.76%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    For this problem, you will write a program that takes a (possibly long) string of decimal digits, and outputs the permutation of those decimal digits that has the next larger value (as a decimal number)

    than the input number. For example:

    123 -> 132

    279134399742 -> 279134423799

    It is possible that no permutation of the input digits has a larger value. For example, 987.

    输入

    The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set is a single line that contains the data set number, followed by a space, followed by up to 80 decimal digits which is the input value.

    输出

    Description

    For this problem, you will write a program that takes a (possibly long) string of decimal digits, and outputs the permutation of those decimal digits that has the next larger value (as a decimal number)

    than the input number. For example:

    123 -> 132

    279134399742 -> 279134423799

    It is possible that no permutation of the input digits has a larger value. For example, 987.

    Input

    The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set is a single line that contains the data set number, followed by a space, followed by up to 80 decimal digits which is the input value.

    Output

    For each data set there is one line of output. If there is no larger permutation of the input digits, the output should be the data set number followed by a single space, followed by the string BIGGEST. Ifthere is a solution, the output should be the data set number, a single space and the next larger permutation of the input digits.

    Sample Input

    3
    1 123
    2 279134399742
    3 987

    Sample Output

    1 132
    2 279134423799
    3 BIGGEST

    Hint

    使用next_permutation的,判cheat且封号。

    Source

    样例输入

    3
    1 123
    2 279134399742
    3 987

    样例输出

    1 132
    2 279134423799
    3 BIGGEST

    提示

    使用next_permutation的,判cheat且封号。


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部