QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100
Estadísticas

Martin 正在参加一门线性代数课。不用说,讲课的教授是全宇宙最无聊的人。黑板上写着一个 $N \times M$ 的矩阵。矩阵中的一些条目是字母(英文字母),而另一些条目是空白的。以下是一个 $6 \times 8$ 大小的矩阵示例:

$$ \begin{bmatrix} k & l & & n & d & i & & \\ & & & & c & & & \\ & & & & & i & h & \\ j & & a & & & & & \\ & & c & b & & & & \\ & & c & & & e & f & \end{bmatrix} $$

Martin 完全不知道这个矩阵代表什么。他感到非常无聊,以至于在过去的 30 分钟里根本没听课。然而,Martin 有着极其丰富的想象力。他想象矩阵突然受到了重力的影响,所有的字母都在矩阵中向下滑动,直到每个字母要么“到达底部”,要么“撞到它下方的字母”。在第一阶段,上述矩阵变为:

$$ \begin{bmatrix} & & & & & & & \\ & & & & & & & \\ & & & & & & & \\ & & l & & & i & & \\ k & c & a & d & i & h & & \\ j & c & b & n & c & e & f & \end{bmatrix} $$

此后,重力方向改变,现在将字母向左拉。我们现在处于第二阶段。同样,所有的字母都向左滑动,直到每个字母要么“到达左侧边界”,要么“撞到它左侧的字母”。于是,之前的矩阵变为:

$$ \begin{bmatrix} & & & & & & & \\ & & & & & & & \\ & & & & & & & \\ l & i & & & & & & \\ k & c & a & d & i & h & & \\ j & c & b & n & c & e & f & \end{bmatrix} $$

Martin 在脑海中一直重复这个过程,直到这门无聊的课程结束。当然,在每个阶段之后,即在所有字母都到达各自的目的地之后,重力可能会改变方向(方向有四种可能:左、右、上、下)。

任务

编写一个程序,根据给定的重力方向变化序列,确定矩阵中所有字母的最终位置。

输入格式

第一行包含三个整数 $N$、$M$ 和 $K$,其中 $N \times M$ 是矩阵的大小,$K$ 是阶段数。

第二行包含一个长度为 $K$ 的字符串,由字母 L、R、U 和 D 组成,分别代表每个阶段的重力方向(左、右、上、下)。

最后 $N$ 行代表矩阵。每行包含 $M$ 个字符。字符为小写英文字母或代表空白条目的“.”(点)。

数据范围

  • $1 \le N, M \le 100$
  • $0 \le K \le 100$

输出格式

输出 Martin 在课程结束时得到的矩阵。矩阵的格式应与输入数据中的格式相同。

样例

输入格式 1

6 8 5
DLURD
k.l.ndi.
.....c..
......ih
j..a....
..cb....
..c...ef

输出格式 1

........
........
........
......hf
..iadice
.lkcbnjc

输入格式 2

3 3 0
a..
.b.
..x

输出格式 2

a..
.b.
..x

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.