CF496B.Secret Combination

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

你得到了一个带组合锁的盒子。锁上有一个显示 $ n $ 位数字的显示屏。盒子上有两个按钮,每个按钮都会改变显示屏上的数字。你很快发现:第一个按钮将所有数字加 $ 1 $(所有数字 $ 9 $ 变为 $ 0 $),第二个按钮将显示屏上的所有数字向右循环移动一位(最后一位数字变为第一位)。例如,若显示屏当前显示数字 $ 579 $,则按下第一个按钮后,显示屏将显示 $ 680 $;在此之后再按下第二个按钮,显示屏将显示 $ 068 $。

你知道,当显示屏显示出通过以某种顺序按动按钮所能得到的最小可能数字时,锁便会打开。在比较数字大小时,前导零被忽略。现在你的任务是找出这个目标数字。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000)—— 显示屏上的数字个数。

第二行包含 nn 个数字 —— 显示屏的初始状态。

输出格式

Print a single line containing n digits — the desired state of the display containing the smallest possible number.

输出一行,包含 n 个数字——即显示屏的目标状态,该状态表示可能的最小数字。

输入输出样例

  • 输入#1

    3
    579

    输出#1

    024
  • 输入#2

    4
    2014

    输出#2

    0142

输入解题思路,AI测评打分。不知道怎么写?

首页