对于 M × N 表中坐标为 (x, y) 的单元格,打印其邻居的坐标。具有共同边的单元称为邻居。给出了自然数 M、N、x、y。以任意顺序将该单元格的邻居的坐标对输出到输出文件中。
出于某种原因,它给出了 0 分,尽管我用数字代替了,就像答案是正确的一样。
M, N, x, y = int(input()), int(input()), int(input()), int(input())
if M != 1 and N != 1:
if x == 1 and y == 1:
print(x + 1, y)
print(x, y + 1)
elif x == 1 and y == N:
print(x + 1, y)
print(x, y - 1)
elif x == M and y == 1:
print(x - 1, y)
print(x, y + 1)
elif x == M and y == N:
print(x - 1, y)
print(x, y - 1)
elif x == 1:
print(x + 1, y)
print(x, y + 1)
print(x, y - 1)
elif x == M:
print(x - 1, y)
print(x, y + 1)
print(x, y - 1)
elif y == 1:
print(x - 1, y)
print(x, y + 1)
print(x + 1, y)
elif y == N:
print(x - 1, y)
print(x, y - 1)
print(x + 1, y)
else:
print(x - 1, y)
print(x + 1, y)
print(x, y + 1)
print(x, y - 1)
else:
if M == 1 and N != 1:
if y == 1:
print(x, y + 1)
elif y == N:
print(x, y - 1)
else:
print(x, y + 1)
print(x, y - 1)
elif N == 1 and M != 1:
if x == 1:
print(x + 1, y)
elif x == M:
print(x - 1, y)
else:
print(x + 1, y)
print(x - 1, y)
也许是这样的。让我们制作一张带有一组坐标变化的表格。我们将显示那些没有超出矩阵的
然后让我们打开我的循环,把它变成一个线性记录
根据您的输入: