302566: CF496B. Secret Combination

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Secret Combination

题意翻译

给定一个长度为 n 的只含数字的字符串,现在可以有两个操作: - 1.将字符串所有字符右移一位(最后一位变成第一位); - 2.将字符串所有字符加一('9' 变成 '0')。 -------- 求通过这样的操作(次数不限)得到的字典序最小的字符串是什么?

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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

输入输出样例

输入样例 #1

3
579

输出样例 #1

024

输入样例 #2

4
2014

输出样例 #2

0142

Input

题意翻译

给定一个长度为 n 的只含数字的字符串,现在可以有两个操作: - 1.将字符串所有字符右移一位(最后一位变成第一位); - 2.将字符串所有字符加一('9' 变成 '0')。 -------- 求通过这样的操作(次数不限)得到的字典序最小的字符串是什么?

加入题单

上一题 下一题 算法标签: