版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huanhuanq1209/article/details/82808040
第一题:
顺时针输出矩阵元素:
def printMatrix(matrix):
res = []
while matrix:
res += matrix.pop(0)
if matrix and matrix[0]:
for row in matrix:
res.append(row.pop())
if matrix:
res += matrix.pop()[::-1]
if matrix and matrix[0]:
for row in matrix[::-1]:
res.append(row.pop(0))
return res
if __name__=='__main__':
a = raw_input()
print a
result = []
b = a.split('],[')
print b
for i in range(len(b)):
if i == 0:
t = b[i].lstrip('[[')
cat = t.split(',')
result.append(cat)
elif i == len(b) - 1:
t = b[i].rstrip(']]')
cat = t.split(',')
result.append(cat)
else:
cat = b[i].split(',')
result.append(cat)
print ','.join(printMatrix(result))
# [[2,3,6],[5,5,9],[3,6,9]]
#2,3,6,9,9,6,3,5,5
运行结果:
蓝瘦。。。。。。。就剩一句了,没写到笔试网页上!o(╥﹏╥)o