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. [转载]Selenium実行中にJavaScriptのコードを実行する

    Selenium実行中にJavaScriptのコードを実行する JavaScriptで画面の値を取得/設定するコードをメモ. WebDriverEx.cs // JavaScriptを実行(戻り値なし ...

  2. URAL题解一

    URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...

  3. 004ICMP-type对应表

    一次在某个防火墙配置策略里看到如下的代码: iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT iptables -A FORWARD -p icmp ...

  4. linux系统磁盘挂载

    1.查看系统磁盘挂载情况 fdisk -l 2.格式化磁盘 mkfs -t ext3 /dev/sdb 3.挂在磁盘 mount /dev/sdb /disk2 4.查看磁盘挂载情况 df -h 5. ...

  5. CentOS 7 中 Docker 的安装

    CentOS 7 中 Docker 的安装 Docker 软件包已经包括在默认的 CentOS-Extras 软件源里.因此想要安装 docker,只需要运行下面的 yum 命令: [root@loc ...

  6. 模块定义文件.def

    一作用 DLL中导出函数的声明有两种方式:一种为在函数声明中加上__declspec(dllexport),这里不再举例说明:另外一种方式是采用模块定义(.def) 文件声明,.def文件为链接器提供 ...

  7. Python抓取微博评论(二)

    对于新浪微博评论的抓取,首篇做的时候有些考虑不周,然后现在改正了一些地方,因为有人问,抓取评论的时候“爬前50页的热评,或者最新评论里的前100页“,这样的数据看了看,好像每条微博的评论都只能抓取到前 ...

  8. Merge k Sorted Lists——分治与堆排序(需要好好看)

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 1 ...

  9. Numpy narray对象的属性分析

    参考官方文档链接: narray是Numpy的基本数据结构,本文主要分析对象的属性(可通过.进行访问) 1:导入numpy: import numpy as np 2:初始化narray对象: > ...

  10. PHP 标准AES加密算法类

    分享一个标准PHP的AES加密算法类,其中mcrypt_get_block_size('rijndael-128', 'ecb');,如果在不明白原理的情况下比较容易搞错,可以通过mcrypt_lis ...