当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1802:Ancient Plates

题目描述
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.
输入解释
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.
输出解释
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.
输入样例
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
输出样例
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.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-1802

最后修改于 2020-10-29T06:14:26+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 30000