NC25050. [USACO 2007 Feb L]Rows and Columns
描述
输入描述
Line 1: Two space-separated integers, respectively: R and C
Lines 2..R*C+1: Line i+1 lists a single integer that is the serial number of entry i in the column-ordered list Jay created.
输出描述
Lines 1..R*C: Line i contains a single integer that is entry i in the proper row-sorted list.
示例1
输入:
3 3 1 8 7 2 9 6 3 4 5
输出:
1 2 3 8 9 4 7 6 5
说明:
A 3 x 3 spiral as above:Go 解法, 执行用时: 6ms, 内存消耗: 984K, 提交时间: 2023-08-18 09:58:18
package main import "fmt" func main() { rows, cols, d := 0, 0, 0 fmt.Scanf("%d %d\n", &rows, &cols) matrix := make([][]int, rows) for i := 0; i < rows; i++ { matrix[i] = make([]int, cols) } for i := 0; i < rows * cols; i++ { fmt.Scanln(&d) matrix[i % rows][i / rows] = d } for i := 0; i < rows; i++ { for j := 0; j < cols; j++ { fmt.Println(matrix[i][j]) } } }
Python3 解法, 执行用时: 43ms, 内存消耗: 4556K, 提交时间: 2023-08-18 09:47:06
rows, cols = map(int, input().split()) matrix = [['0' for i in range(cols)] for j in range(rows)] for i in range(rows * cols): matrix[i % rows][i // rows] = input() print('\n'.join('\n'.join(row) for row in matrix))