CodeForces 496B Secret Combination
2015-08-30 20:18
513 查看
Secret Combination
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 496B
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
Output
Input
Output
View Code
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 496B
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[1005]; int b[1005]; while(scanf("%d",&n)!=EOF) { b[0]=0; for(i=1;i<1000;i++) b[i]=9; scanf("%s",a); for(i=0;i<n;i++) { int x='9'-a[i]+1; for(j=1;j<n;j++) { int y=(a[(i+j)%n]-'0'+x)%10; if(y<b[j]) { for(k=1;k<n;k++) { b[k]=(a[(i+k)%n]-'0'+x)%10; } break; } else if(y>b[j]) { break; } } } for(i=0;i<n;i++) printf("%d",b[i]); printf("\n"); } return 0; }
View Code
相关文章推荐
- CodeForces 483B Friends and Presents
- Android开发详解之onTouch和onClick详解
- poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)
- CodeForces 490C Hacking Cypher
- virtualbox谨记:win7上只有4.3.x的版本支持ubuntu14.04.3虚拟机安装Oracle Rac,其他的版本3.x和5.0.2(至2015-08-30)均不可以
- linux 磁盘管理工具
- C语言基础知识之(十五):指针和函数
- java并发编程第六章(3)使用阻塞式线程安全列表
- ALTERA DE2 之 verilog HDL 学习笔记01 程序的并行
- Windows 多进程通信API总结
- .NET六大剑客:栈、堆、值类型、引用类型、装箱和拆箱
- 字符串最后一个单词的长度(华为在线训练)
- CodeForces 483C Diverse Permutation
- android-屏幕适配(一)
- Alien Order
- Linux进程间通信---有名管道 代码实现
- RESTEasy常用注解
- CodeForces 478C Table Decorations
- C语言基础知识之(十四):指针和字符数组、字符串数组
- CodeForces #318 (div1) B.Bear and Blocks