B. Secret Combination
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
input
3
579
output
024
input
4
2014
output
0142

/*题目大意:给一整数,有两种方式、1、每位加1,其中9变为0,但不进位。2、整体向后移动一位、最后一位移动到首位
* 问经过若干操作1与2后得到的最小数是多少
*算法分析:可将环问题转换为链进行解决。然后每位累加,加10次依次进行比较即可,暴力完成
*/ #include <bits/stdc++.h>
using namespace std; char a[2200];
char b[2200], ans[2200]; int main() {
int n;
scanf("%d ",&n);
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(ans, 0, sizeof(ans));
for (int i = 0; i<n; i++) scanf("%c",&a[i]);
strcpy(ans, a);
//cout << ans << endl;
for (int i = 0; i<n; i++) a[n+i] = a[i]; int t = 0;
while (t <= 9) {
for (int i = 0; i<2*n; i++) {
int tmp = a[i] - 48;
tmp = (tmp+1) % 10;
a[i] ='0' + tmp;
}
//cout << a << endl;
t ++ ;
for (int i = 0; i<n; i++) {
int flag = 0;
for (int j = i; j<i+n; j++) b[flag++] = a[j];
if (strcmp(ans, b) > 0) strcpy(ans, b);
//cout << b << endl;
}
//cout << ans << endl;
}
cout << ans << endl;
return 0;
}

B. Secret Combination的更多相关文章

  1. CodeForces 496B Secret Combination

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

  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 暴力水题

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

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

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

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

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

  6. 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 ...

  7. A - Combination Lock

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

  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 540

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

随机推荐

  1. bzoj 4345: [POI2016]Korale

    Description 有n个带标号的珠子,第i个珠子的价值为a[i].现在你可以选择若干个珠子组成项链(也可以一个都不选),项链的价值为所有珠子的价值和.现在给所有可能的项链排序,先按权值从小到大排 ...

  2. Linux第三节整理 、增删改查、用户管理

    帮助+基本文件管理+用户管理 1.怎么查看命令帮助 ls --help man ls :查看命令/man 5 file:查看配置文件 2.基本文件管理,通过{查,建,删,改} 四个维度介绍了不同的命令 ...

  3. js中的call()方法与apply()方法

    摘自:http://blog.csdn.net/chelen_jak/article/details/21021101 在web前端开发过程中,我们经常需要改变this指向,通常我们想到的就是用cal ...

  4. K:java中properties文件的读写

    Properties类与.properties文件:   Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形式来保存属性集的类,不过Properties有特殊 ...

  5. JS对时间的操作

    JS时间操作大全 1.获取每个月的开始和结束. 2.获取每个季度的开始和结束. 3.获取当前季度. 4.把日期转换为字符串(支持各种格式) ... 5.未完待续,不断添加 String.prototy ...

  6. linux ext4无法使用超过16T磁盘的解决办法

    大磁盘使用问题 问题:当所要挂载的设备大于16T的时候,可以用parted正常分区,但是分区完成之后,无法格式化, 报错:Size of device /dev/sdb1 too big to be ...

  7. celery出现警告或异常的解决方式

    做个笔记,记录下使用celery踩过的坑,不定期更新.  warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED)) 我用的是Flask,所以在Fl ...

  8. 基于JerseyToken安全设计

    网上Jersey中文资料不多,更别提其他了.本人跟进项目具体需求弄了简单的api认证机制 基本流程图 后端登录退出代码: @Path("Account") public class ...

  9. Mysql:执行source sql脚本时,出现:error 2

    Centos下部署mysql: 1.yum -y install mysql*; 2.service mysqld start; 3.chkconfig mysqld on; 4.设置用户名和密码:m ...

  10. Oracle loop循环无法插入数据

    以下的测试基于scott用户下的emp表 首先用while循环进行测试,向emp表插入999条数据 declare i emp.empno; begin loop insert into emp(em ...