[求助]蛇行矩阵
创建蛇行矩阵 起始位置是左上角,然后依次顺时针增减def main(n):
tot=1
a=[ for i in range(n)]
x=0
y=n-1
# a=tot
print(a)
while(tot<n*n+1):
while(x+1<n)and(not(a)):
a=tot
x+=1
tot+=1
while(y-1>=0)and(not(a)):
a=tot
y-=1
tot+=1
while(x-1>=0)and(not(a)):
a=tot
x-=1
tot+=1
while(y+1<n)and(not(a)):
a=tot
y+=1
tot+=1
print(a)
# a=1
# tot=a[]
main(3)
想问一下为什么最后一位总是为零,难道是没有赋值附上去吗
直接举例说出你的要求 凌九霄 发表于 2018-6-28 18:43
直接举例说出你的要求
你跑下我的程序就知道了
页:
[1]