Secret Combination

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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.

Input

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.

Output

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

Sample Input

Input
3
579
Output
024
Input
4
2014
Output
0142
 #include <stdio.h>
#include <string.h>
int main()
{
int n;
int i,j,k;
char a[];
int b[];
while(scanf("%d",&n)!=EOF)
{
b[]=;
for(i=;i<;i++)
b[i]=;
scanf("%s",a);
for(i=;i<n;i++)
{
int x=''-a[i]+;
for(j=;j<n;j++)
{
int y=(a[(i+j)%n]-''+x)%;
if(y<b[j])
{
for(k=;k<n;k++)
{
b[k]=(a[(i+k)%n]-''+x)%;
}
break;
}
else if(y>b[j])
{
break;
}
}
}
for(i=;i<n;i++)
printf("%d",b[i]);
printf("\n");
}
return ;
}

CodeForces 496B Secret Combination的更多相关文章

  1. codeforces 496B. Secret Combination 解题报告

    题目链接:http://codeforces.com/problemset/problem/496/B 题目意思:给出 n 位数你,有两种操作:1.将每一位数字加一(当某一位 > 9 时只保存个 ...

  2. cf 496B Secret Combination

    题目链接:B. Secret Combination You got a box with a combination lock. The lock has a display showing n d ...

  3. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  4. Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题

    B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. B. Secret Combination

    B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. [Codeforces]1263D Secret Passwords

    题目 One unknown hacker wants to get the admin's password of AtForces testing system, to get problems ...

  7. Codeforces Round #301 (Div. 2) A. Combination Lock 暴力

    A. Combination Lock Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...

  8. Codeforces 540A - Combination Lock

    Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he ...

  9. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

随机推荐

  1. 夺命雷公狗ThinkPHP项目之----企业网站25之网站前台面包屑导航URL的完善

    如果想取出面包屑导航的url那么就必须在model层里面进行多取一个了: <?php namespace Home\Model; use Think\Model; class CategoryM ...

  2. [CrunchBang]禁止“桌面上鼠标滚轮切换工作区桌面“

    鼠标滚轮切换虚拟桌面相关问题, 编辑 ~/.config/openbox/rc.xml 在   <context name="Desktop">段: <mouse ...

  3. Controller 接口控制器详解

    Controller 控制器,是 MVC 中的部分 C,为什么是部分呢?因为此处的控制器主要负责功能处理部分:1.收集.验证请求参数并绑定到命令对象:2.将命令对象交给业务对象,由业务对象处理并返回模 ...

  4. python通过win32api轻松获取控件的属性值

    1.如何利用句柄操作windows窗体 首先,获得窗体的句柄  win32api.FindWindows() 第二,获得窗体中控件的id号,spy++ 第三,根据控件的ID获得控件的句柄(hwnd)  ...

  5. ch2-4:遇到嵌套列表进行缩进打印

    1.增加一个参数来控制缩进打印:level '''这是一个模块,可以打印列表,其中可能包含嵌套列表''' def print_list(the_list,level): ""&qu ...

  6. top.location.href和localtion.href有什么不同

    top.location.href=”url”          在顶层页面打开url(跳出框架) self.location.href=”url”         仅在本页面打开url地址 pare ...

  7. LoadRunner并发用户和集合点的深入讨论

    看到51上三个高手Zee, 大漠飞鹰,xingcyx的一场非常精彩的关于并发用户数和集合点的讨论,很有意义.如果对这两个概念不清楚的朋友,一定要仔细领悟了. 故事开始于xingcyx的一番话: 声明: ...

  8. python读入文件

    举例说明吧,路径一定要带转义符‘\’,下面的例子中,每一行是一个样本的feature >>> myfile=open("D:\\301\\graduate_thesis\\ ...

  9. let和expr比较

    1.空格 let:要求任何操作符两边不能含有空格 expr:必须有空格 2.运算符转义 expr:要求 let:没有要求 [xiluhua@vm-xiluhua][~]$ let * -bash: l ...

  10. ubunt1204安装配置vsftp

    本文将搭建一个最简单的ftp服务,即通过root用户可进行登录.上传.下载,具体步骤如下: 1.安装vsftpd服务 sudo apt-get install vsftpd 2.编辑vsftp配置文件 ...