Combination Lock

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Finally, you come to the interview room. You know that a Microsoft interviewer is in the room though the door is locked. There is a combination lock on the door. There are N rotators on the lock, each consists of 26 alphabetic characters, namely, 'A'-'Z'. You need to unlock the door to meet the interviewer inside. There is a note besides the lock, which shows the steps to unlock it.

Note: There are M steps totally; each step is one of the four kinds of operations shown below:

Type1: CMD 1 i j X: (i and j are integers, 1 <= i <= j <= N; X is a character, within 'A'-'Z')

This is a sequence operation: turn the ith to the jth rotators to character X (the left most rotator is defined as the 1st rotator)

For example: ABCDEFG => CMD 1 2 3 Z => AZZDEFG

Type2: CMD 2 i j K: (i, j, and K are all integers, 1 <= i <= j <= N)

This is a sequence operation: turn the ith to the jth rotators up K times ( if character A is turned up once, it is B; if Z is turned up once, it is A now. )

For example: ABCDEFG => CMD 2 2 3 1 => ACDDEFG

Type3: CMD 3 K: (K is an integer, 1 <= K <= N)

This is a concatenation operation: move the K leftmost rotators to the rightmost end.

For example: ABCDEFG => CMD 3 3 => DEFGABC

Type4: CMD 4 i j(i, j are integers, 1 <= i <= j <= N):

This is a recursive operation, which means:

If i > j:
Do Nothing
Else:
CMD 4 i+1 j
CMD 2 i j 1

For example: ABCDEFG => CMD 4 2 3 => ACEDEFG

输入

1st line:  2 integers, N, M ( 1 <= N <= 50000, 1 <= M <= 50000 )

2nd line: a string of N characters, standing for the original status of the lock.

3rd ~ (3+M-1)th lines: each line contains a string, representing one step.

输出

One line of N characters, showing the final status of the lock.

提示

Come on! You need to do these operations as fast as possible.

样例输入
7 4
ABCDEFG
CMD 1 2 5 C
CMD 2 3 7 4
CMD 3 3
CMD 4 1 7
样例输出
HIMOFIN

 import java.util.Scanner;

 public class Main {

     public static void main(String[] argv){

         Scanner in = new Scanner(System.in);
int M = in.nextInt();
int N = in.nextInt();
in.nextLine();
String source = in.nextLine();
String[] move= new String[N];
for(int i=0; i<N;i++){
move[i]=in.nextLine();
}
in.close();
int[] int_Source = new int[M];
char[] c_Source = source.toCharArray();
for(int i=0; i<M;i++){
int_Source[i]= c_Source[i]-65;
}
for(int i=0; i<N;i++){
String[] temp = move[i].split(" ");
switch(temp[1]){
case "1":
if(temp[4].length()==1)
oneMethod(int_Source,Integer.parseInt(temp[2]),Integer.parseInt(temp[3]),((int)(temp[4].toCharArray()[0]))-65);
break;
case "2":
secondMethod(int_Source,Integer.parseInt(temp[2]),Integer.parseInt(temp[3]),Integer.parseInt(temp[4]));
break;
case "3":
thirdMethod(int_Source,Integer.parseInt(temp[2]));
break;
case "4":
fourthMethod(int_Source,Integer.parseInt(temp[2]),Integer.parseInt(temp[3]));
break;
}
/*
for(int out:int_Source ){
System.out.println(out+" ");
}
System.out.println();
*/
}
for(int out:int_Source ){
System.out.print((char)(out+65));
}
} public static void oneMethod(int[] s, int i, int j,int k){ for(int p=i-1; p<j; p++){
s[p]=k;
s[p]=s[p]%26;
} } public static void secondMethod(int[] s, int i, int j,int k){ for(int p=i-1; p<j; p++){
s[p]=s[p]+k;
s[p]=s[p]%26;
}
} public static void thirdMethod(int[] s, int i){
int[] temp =new int[s.length];
for(int q=0; q<s.length;q++){
temp[q]=s[q];
}
for(int p=0; p<s.length; p++){
if(i+p<s.length)
s[p]=temp[i+p];
else
s[p]=temp[(i+p)%s.length];
s[p]=s[p]%26;
} } public static void fourthMethod(int[] s, int i, int j){ for(int p=i-1;p<j;p++ ){
s[p]=s[p]+p-i+2;
s[p]=s[p]%26;
}
} }

Hiho----微软笔试题《Combination Lock》的更多相关文章

  1. hiho一下 第一百零七周 Give My Text Back(微软笔试题)

    题目1 : Give My Text Back 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 To prepare for the English exam Littl ...

  2. 微软笔试题-highways

    题目大意 一条单向的高速公路上有N辆车,在0时刻,每辆车分别在起点A[0],A[1]....处开始从北向南出发,每辆车有个终点B[0],B[1]....且每辆车有个限制速度 V[0],V[1]... ...

  3. C/C++ 笔试题

    /////转自http://blog.csdn.net/suxinpingtao51/article/details/8015147#userconsent# 微软亚洲技术中心的面试题!!! 1.进程 ...

  4. 收藏所用C#技术类面试、笔试题汇总

    技术类面试.笔试题汇总 注:标明*的问题属于选择性掌握的内容,能掌握更好,没掌握也没关系. 下面的参考解答只是帮助大家理解,不用背,面试题.笔试题千变万化,不要梦想着把题覆盖了,下面的题是供大家查漏补 ...

  5. C/C++笔试题(很多)

    微软亚洲技术中心的面试题!!! .进程和线程的差别. 线程是指进程内的一个执行单元,也是进程内的可调度实体. 与进程的区别: (1)调度:线程作为调度和分配的基本单位,进程作为拥有资源的基本单位 (2 ...

  6. Unity3d笔试题大全

    1.       [C#语言基础]请简述拆箱和装箱. 答: 装箱操作: 值类型隐式转换为object类型或由此值类型实现的任何接口类型的过程. 1.在堆中开辟内存空间. 2.将值类型的数据复制到堆中. ...

  7. Java 面试/笔试题神整理 [Java web and android]

    Java 面试/笔试题神整理 一.Java web 相关基础知识 1.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并 ...

  8. NET出现频率非常高的笔试题

    又到了金三银四的跳槽季,许多朋友又开始跳槽了,这里我简单整理了一些出现频率比较高的.NET笔试题,希望对广大求职者有所帮助. 一..net基础 1.  a=10,b=15,请在不使用第三方变量的情况下 ...

  9. 嵌入式Linux C笔试题积累(转)

    http://blog.csdn.net/h_armony/article/details/6764811 1.   嵌入式系统中断服务子程序(ISR) 中断是嵌入式系统中重要的组成部分,这导致了很 ...

随机推荐

  1. IT人员必备linux安全运维之Ssh用途、安全性、身份认证以及配置……【转】

    SSH一般用途 提供shell,解决telnet不安全的传输 1.修改默认ssh默认端口 vi /etc/ssh/sshd_config 修改之后重启 >systemctl restart ss ...

  2. Deep Learning基础--word2vec 中的数学原理详解

    word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了很多人的关注.由于 word2vec 的作者 Tomas Miko ...

  3. The algorithm of entropy realization

    近似熵的一种快速实用算法 Pincus提出的近似熵算法中有很多冗余的计算,效率低,速度慢,不利于实际应用,洪波等人在定义的基础上引入二值距离矩阵的概率,提出了一种实用快速的算法. function A ...

  4. Java的BIO,NIO,AIO

    Java中的IO操作可谓常见.在Java的IO体系中,常有些名词容易让人困惑不解.为此,先通俗地介绍下这些名词. 1 什么是同步? 2 什么是异步? 3 什么是阻塞? 4 什么是非阻塞? 5 什么是同 ...

  5. GitHub vs GitLab:它们有什么区别?

    查看原文GitLab vs. GitHub: How Are They Different? 两者都是基于web的Git repositories(仓库),拥有流水线型的web开发流程,它们为开发团队 ...

  6. curl 发送请求的时候报错

    AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see ...

  7. Java打包问题之一:打包出现java.io.IOException: invalid header field

    前言 java的打包工具jar有时候会出一些莫名其妙的问题,比如不合法的头部字段等等.这些问题之前也没注意,因为一直是用eclipse打包.后来在公司的时候,要求统一编写shell脚本来进行打包. 其 ...

  8. linux下redis的安装与部署

    一.Redis介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...

  9. MySQL5.7 centos7.2 yum 安装

    1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/  # 下载mysql源安装包 shell> wge ...

  10. 反片语(UVa156)

    题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&a ...