DSTJZ


私信TA

用户名:dotcpp0721777

访问量:4523

签 名:

天下难事,必作于易;天下大事,必作于细。

等  级
排  名 50
经  验 11010
参赛次数 13
文章发表 312
年  龄 18
在职情况 学生
学  校 狗熊岭23届毕业生
专  业

  自我简介:

TA的其他文章


参考代码:

#   设置四个边界,层层遍历

row, column = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(row)]

left, right, top, bottom = 0, column - 1, 0, row - 1
while left <= right and top <= bottom:
    for k in range(left, right + 1):
        print(arr[top][k])
    for k in range(top + 1, bottom + 1):
        print(arr[k][right])
    if left < right and top < bottom:
        for k in range(right - 1, left, -1):
            print(arr[bottom][k])
        for k in range(bottom, top, -1):
            print(arr[k][left])
    left += 1
    right -= 1
    top += 1
    bottom -= 1


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区