CCF CSP认证201412-2 Z字扫描

# n,m=input().split()
# n,m=int(n),int(m)
import time
# c1 = time.perf_counter()
n = int(input())
data = list()
for i in range(n):
    s=input().split()
    for j in range(n):
        s[j]=int(s[j])
    data.append(s)
result = list()
i = 0#hang
j = 0
flag = 1
c1 = time.perf_counter()
while(len(result)<n*n):
    if(j==0 and flag==1):
        # if(i%2==0):
            if(i+1<n):
                result.append(data[j][i])
                i += 1
                flag = -1
                continue
            else:
                result.append(data[j][i])
                j += 1
                flag = -1
                continue
    elif(i==0 and flag==-1):
            if (j + 1 < n):
                result.append(data[j][i])
                j += 1
                flag = 1
                continue
            else:
                result.append(data[j][i])
                i += 1
                flag = 1
                continue
    elif (i == n-1 and j!=0 and flag == 1):
            if (j + 1 < n):
                result.append(data[j][i])
                j += 1
                flag = -1
                continue
            else:
                result.append(data[j][i])
                i += 1
                flag = -1
                continue
    elif (j == n-1 and i!=0 and flag == -1):
            if (i + 1 < n):
                result.append(data[j][i])
                i += 1
                flag = 1
                continue
            else:
                result.append(data[j][i])
                j += 1
                flag = 1
                continue
    elif(flag==-1):
        result.append(data[j][i])
        i -= 1
        j += 1
    else:
        result.append(data[j][i])
        i += 1
        j -= 1
print(result)
print(time.perf_counter()-c1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值