我知道有类似的问题,但没有人对这种特定类型的格式有答案。对于codeforces问题,我需要这样输入矩阵:0 0 0 0 00 0 0 0 10 0 0 0 00 0 0 0 00 0 0 0 0我想将它存储为一个矩阵,其中 m[i][j] 与上面的输入完全相同。例如,我想将输入存储为一个矩阵,其中 [4][1] 与 1 相关。如何在 python3 中获取此输入?如果有帮助,我在此处附上了问题:https ://codeforces.com/problemset/problem/263/A 。唯一需要注意的是矩阵总是 5x5。
1 回答

MYYA
TA贡献1868条经验 获得超4个赞
利用:
N = 5 # Shape of the square matrix(NxN)
matrix = [list(map(int, input().split())) for _ in range(N)]
print(matrix)
print("Element at 2 row and 5 column is:", matrix[1][4])
输出:
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]
Element at 2 row and 5 column is: 1
添加回答
举报
0/150
提交
取消