102371: [AtCoder]ABC237 B - Matrix Transposition

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

You are given an $H$-by-$W$ matrix $A$.
The element at the $i$-th row from the top and $j$-th column from the left of $A$ is $A_{i,j}$.

Let $B$ be a $W$-by-$H$ matrix whose element at the $i$-th row from the top and $j$-th column from the left equals $A_{j, i}$.
That is, $B$ is the transpose of $A$.

Print $B$.

Constraints

  • $1\leq H,W \leq 10^5$
  • $H \times W \leq 10^5$
  • $1 \leq A_{i,j} \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$H$ $W$
$A_{1,1}$ $A_{1,2}$ $\ldots$ $A_{1,W}$
$A_{2,1}$ $A_{2,2}$ $\ldots$ $A_{2,W}$
$\vdots$
$A_{H,1}$ $A_{H,2}$ $\ldots$ $A_{H,W}$

Output

Print $B$ in the following format:

$B_{1,1}$ $B_{1,2}$ $\ldots$ $B_{1,H}$
$B_{2,1}$ $B_{2,2}$ $\ldots$ $B_{2,H}$
$\vdots$
$B_{W,1}$ $B_{W,2}$ $\ldots$ $B_{W,H}$

Sample Input 1

4 3
1 2 3
4 5 6
7 8 9
10 11 12

Sample Output 1

1 4 7 10
2 5 8 11
3 6 9 12

For example, we have $A_{2,1}=4$, so the element at the $1$-st row from the top and $2$-nd column from the left of the transpose $B$ is $4$.


Sample Input 2

2 2
1000000000 1000000000
1000000000 1000000000

Sample Output 2

1000000000 1000000000
1000000000 1000000000

Input

题意翻译

给出行列为 $H,W$ 的序列 $A$,序列 $B$ 满足 $b_{i, j} = a_{j, i}$,输出 $B$。 $\text{translate by @fengguengxi}$

Output

得分:200分

问题描述

给你一个 $H$ 行 $W$ 列的矩阵 $A$。

$A$ 中从上数第 $i$ 行、从左数第 $j$ 列的元素为 $A_{i,j}$。

令 $B$ 是一个 $W$ 行 $H$ 列的矩阵,其中从上数第 $i$ 行、从左数第 $j$ 列的元素等于 $A_{j, i}$。

即 $B$ 是 $A$ 的转置。

限制条件

  • $1\leq H,W \leq 10^5$
  • $H \times W \leq 10^5$
  • $1 \leq A_{i,j} \leq 10^9$
  • 输入中的所有值都是整数。

输入

从标准输入按以下格式接收输入:

$H$ $W$
$A_{1,1}$ $A_{1,2}$ $\ldots$ $A_{1,W}$
$A_{2,1}$ $A_{2,2}$ $\ldots$ $A_{2,W}$
$\vdots$
$A_{H,1}$ $A_{H,2}$ $\ldots$ $A_{H,W}$

输出

按以下格式输出 $B$:

$B_{1,1}$ $B_{1,2}$ $\ldots$ $B_{1,H}$
$B_{2,1}$ $B_{2,2}$ $\ldots$ $B_{2,H}$
$\vdots$
$B_{W,1}$ $B_{W,2}$ $\ldots$ $B_{W,H}$

样例输入 1

4 3
1 2 3
4 5 6
7 8 9
10 11 12

样例输出 1

1 4 7 10
2 5 8 11
3 6 9 12

例如,我们有 $A_{2,1}=4$,所以转置矩阵 $B$ 中从上数第 $1$ 行、从左数第 $2$ 列的元素是 $4$。


样例输入 2

2 2
1000000000 1000000000
1000000000 1000000000

样例输出 2

1000000000 1000000000
1000000000 1000000000

加入题单

算法标签: