编程介的小学生 2019-09-14 21:33 采纳率: 20.5%
浏览 184

Ancient Plates 程序的代码的编写的过程

Description

Background
Some decades ago archaeologists discovered plates in an ancient temple that were covered with text. While the symbols used were known to the archaeologists, the encryption of the text as a whole has so far been a mystery. However, just last year another temple was discovered in the same area as the first. The interior of this temple was quite similar to the first, so it is believed to have been built at the same time. The second temple contained plates as well, but the contents of these plates looked quite different. After a year of research, the archaeologists developed the theory that these plates contained the code which was needed to decipher the text on the plates found in the first temple.
Problem
Your job is to write a program which automates the process of deciphering the text on the plates by applying the rules which were proposed by the archaeologists.
There are two types of rules: PERM and SHIFT. Both apply to one of the following targets: lines of the text (L), words (W) or characters (C).
A PERM rule consists of the string PERM, followed by a single blank and a letter indicating the target, and one or more pairs of indices separated by blanks. A pair of indices i, j consists of two positive integers i and j separated by just a comma.
Depending on the target, the PERM rule is supposed to do the following for each pair i, j of indices, working with the indices from the left to the right:
L : exchange lines i and j;
W : exchange words i and j in all lines;
C : exchange characters i and j in all words in all lines.
If at least one of the objects to be exchanged does not exist, skip this exchange. Example: PERM W 2,7 asks you to exchange the second and seventh word in all lines, but there might be a line with just five words.Then do nothing in that line, but perform the exchange in all other lines with at least seven words.
A SHIFT rule consists of the string SHIFT, a single blank, the letter indicating the target, another single blank and an integer k. If k = 1 [k = -1], you are supposed to do the following, depending on the target:
L : shift all lines up [down] by one line, with the first [last] line becoming the last [first] line;
W: shift all words in all lines to the left [right] by one word, with the first [last] word in each line becoming the last [first] word.
C : shift all characters in all words to the left [right] by one character, with the first [last] character of each word becoming the last [first] character.
If k >= 0 [k <= 0] is an arbitrary integer, perform the above action for k = 1 [k = -1] just |k| times.
Input

The first line of the input contains the number of scenarios, i.e. the number of plates which have to be deciphered.
For each such plate, you are first given the number l (0 <= l <= 1000) of lines of text on the plate to be deciphered in a single line. In the following l lines, this text is given, with no line exceeding 1000 characters. After that, there is a line containing the number r (0 <= r <= 1000) of rules which have to be applied. The subsequent r lines contain these rules, in the format described above.
The words of the text are considered to be sequences of arbitrary characters (not just letters!), separated by single blanks. No line of the given text will start or end with a blank, but it might be empty altogether.
Output

Start the output for each scenario with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print l lines containing the text after applying all the rules. Print an additional blank line after each scenario.
Sample Input

2
3
First line.
Second line.
Third line.
1
SHIFT L -1
6
ettypr ante e.aid era a
lsemi is an btiingOr itsh at a satncedi of uhglyro nten-twoyi lilonmi
rgeurdedan lolwye ns.u setrnwe iarlsp mra of eht lxayGa elsi a allsm
oeswh ed-dsceneedap flei trelyut sgiaificnntin tlteli ubel enegr aentpl
dne of eht raF tuo in eht cahntedur cwkbtersaa of eht fsabionahleun
iknth gtialdi thceswa rsmfo era so aizmglyan iimrivept atth etyh illst
5
SHIFT W 3
PERM C 4,9 2,3
SHIFT C -2
SHIFT L 1
PERM L 3,9 3,4 1,3
Sample Output

Scenario #1:
Third line.
First line.
Second line.

Scenario #2:
Far out in the uncharted backwaters of the unfashionable end of the
western spiral arm of the Galaxy lies a small unregarded yellow sun.
Orbiting this at a distance of roughly ninety-two million miles is an
utterly insignificant little blue green planet whose ape-descended life
forms are so amazingly primitive that they still think digital watches
are a pretty neat idea.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
    • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
    • ¥15 写论文,需要数据支撑
    • ¥15 identifier of an instance of 类 was altered from xx to xx错误
    • ¥100 反编译微信小游戏求指导
    • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
    • ¥15 学不会递归,理解不了汉诺塔参数变化
    • ¥15 基于图神经网络的COVID-19药物筛选研究
    • ¥30 软件自定义无线电该怎样使用