CF1669G.Fall Down

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a grid with nn rows and mm columns, and three types of cells:

  • An empty cell, denoted with '.'.
  • A stone, denoted with '*'.
  • An obstacle, denoted with the lowercase Latin letter 'o'.

All stones fall down until they meet the floor (the bottom row), an obstacle, or other stone which is already immovable. (In other words, all the stones just fall down as long as they can fall.)

Simulate the process. What does the resulting grid look like?

有一个 nn 行 mm 列的网格,包含三种类型的格子:

  • 空格子,用 . 表示;
  • 石头,用 * 表示;
  • 障碍物,用小写拉丁字母 o 表示。

所有石头均向下掉落,直到碰到地板(最底行)、障碍物,或另一个已固定的石头为止。(换言之,所有石头尽可能地自由下落。)

请模拟该过程。最终的网格是什么样子?

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤501 \leq n, m \leq 50) — the number of rows and the number of columns in the grid, respectively.

Then nn lines follow, each containing mm characters. Each of these characters is either '.', '*', or 'o' — an empty cell, a stone, or an obstacle, respectively.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤501 \leq n, m \leq 50),分别表示网格的行数和列数。

接下来是 nn 行,每行包含 mm 个字符。这些字符中每个均为 '.'、'*' 或 'o',分别表示空单元格、石头或障碍物。

输出格式

For each test case, output a grid with nn rows and mm columns, showing the result of the process.

You don't need to output a new line after each test, it is in the samples just for clarity.

对于每个测试用例,输出一个具有 nn 行和 mm 列的网格,展示该过程的结果。

无需在每个测试用例后输出空行,样例中仅为了清晰起见而添加了空行。

输入输出样例

  • 输入#1

    3
    6 10
    .*.*....*.
    .*.......*
    ...o....o.
    .*.*....*.
    ..........
    .o......o*
    2 9
    ...***ooo
    .*o.*o.*o
    5 5
    *****
    *....
    *****
    ....*
    *****

    输出#1

    ..........
    ...*....*.
    .*.o....o.
    .*........
    .*......**
    .o.*....o*
    
    ....**ooo
    .*o**o.*o
    
    .....
    *...*
    *****
    *****
    *****

输入解题思路,AI测评打分。不知道怎么写?

首页