10137_RunaroundNumbers

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

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

Pro.ID

10137

Title

Runaround Numbers

Title链接

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

AC

50

Submit

124

Ratio

40.32%

时间&空间限制

  • Time Limit: 20000/10000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration:

    • If you start at the left digit (8 in our number) and count that number of digits to the right (wrapping back to the first digit when no digits on the right are available), you'll end up at a new digit (a number which does not end up at a new digit is not a Runaround Number). Consider: 8 1 3 6 2 which cycles through eight digits: 1 3 6 2 8 1 3 6 so the next digit is 6.

    • Repeat this cycle (this time for the six counts designed by the '6') and you should end on a new digit: 2 8 1 3 6 2, namely 2.

    • Repeat again (two digits this time): 8 1

    • Continue again (one digit this time): 3

    • One more time: 6 2 8 and you have ended up back where you started, after touching each digit once. If you don't end up back where you started after touching each digit once, your number is not a Runaround number.

    Given a number M (that has anywhere from 1 through 9 digits), find and print the next runaround number higher than M, which will always fit into an unsigned long integer for the given test data.

    输入

    Multiple test cases. For each case contains a single line with a single integer, M

    输出

    Description

    Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration:

    • If you start at the left digit (8 in our number) and count that number of digits to the right (wrapping back to the first digit when no digits on the right are available), you'll end up at a new digit (a number which does not end up at a new digit is not a Runaround Number). Consider: 8 1 3 6 2 which cycles through eight digits: 1 3 6 2 8 1 3 6 so the next digit is 6.

    • Repeat this cycle (this time for the six counts designed by the '6') and you should end on a new digit: 2 8 1 3 6 2, namely 2.

    • Repeat again (two digits this time): 8 1

    • Continue again (one digit this time): 3

    • One more time: 6 2 8 and you have ended up back where you started, after touching each digit once. If you don't end up back where you started after touching each digit once, your number is not a Runaround number.

    Given a number M (that has anywhere from 1 through 9 digits), find and print the next runaround number higher than M, which will always fit into an unsigned long integer for the given test data.

    Input

    Multiple test cases. For each case contains a single line with a single integer, M

    Output

    For each case output A single line containing the next runaround number higher than the input value, M.

    Sample Input

    81361
    111110

    Sample Output

    81362
    134259

    Source

    样例输入

    81361
    111110

    样例输出

    81362
    134259

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部