编程介的小学生 2017-11-22 16:40 采纳率: 20.5%
浏览 678
已采纳

Robot Encryption

Problem Description
Due to suspicion of cheaters, one of the more paranoid problem setters has started encrypting all messages to the rest of the jury before sending them. He didn't use any standard encryption, however, as he believes those are all part of a giant conspiracy network trying to crush IDI Open from the inside.

Instead, he based it on the fact that the cheaters are likely to be the worst programmers. The decryption requires some programming skill, and should
therefore be safe.

Along with the encrypted message, he sent explanation of how to decrypt it. The only problem now is that not all jury members are able to implement the decryption. This is where we need your help.

You need to help us decrypt these messages by writing a program that does the task. Decryption is performed by simulating a robots movement on a grid. The robot is initially placed in the north-west corner of the grid, facing south. The robot is a simple one, and only accepts three dierent commands:

L turns the robot 90 angle to the left.

R turns the robot 90 angle to the right.

F moves the robot one square forward. If moving forward would cause the robot to fall of the grid, the robot instead makes a 180 angle turn without moving.

Instructions to the robot is given in a series of commandsets. A commandset is a string of commands, with the possible addition of loops. A loop is given on the form "(commandset)number" where number is the number of times the commandset inside the parentheses should be run. Longer sequences of commands can be built up recursively in this fashion. More formally:

commandset ::= instruction+

instruction ::= command | loop

loop ::= "(" commandset ")" number

command ::= R | L | F

number ::= 1 |2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

The decrypted text is the text string obtained by concatenating the characters on the grid positions the robot stands on after executing each commandline.

Input
The first line of input gives T, the number of test scenarios. Each scenario starts with a line containing W and H, separated by a single space, describing the dimensions of the grid. Then follows H lines, each consisting of W characters, making up the grid. After this comes a line containing N, the number of commandlines, followed by the N lines the robot will be executing.

Output
One line per test scenario, containing the decrypted text.

Notes and Constraints
0 < T <= 100
0 < W <= 50
0 < H <= 50
0 < N <= 20

Commandlines will be no longer than 50 characters, and will follow the syntax given in the problem text.

No character with ASCII value lower than 32 or higher than 126 will appear on the robots grid.

Sample Input
1
6 7
012345
6789AB
CDEFGH
IJKLMN
OPQRST
UVWXYZ
_! .,&
12
FFL(F)5
(F)4
(LF)2
(L(R)6L)9
RFRFFF
(L(F)2)2
LF
FLFF
FFFF
LF
FLFF
L(F)4

Sample Output
HELLO WORLD!

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。