Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x=int(input('input first index of matrix: '))
- y=int(input('input second index of matrix: '))
- d=int(input('input digit: '))
- mat=[[ int(input('input: ')) for j in range(y)][::pow(-1, i)] for i in range(x)]
- count=0
- for i in range(x):
- if count==1:
- break
- if pow(-1,i)==1:
- for j in range(y):
- if mat[i][j]>d:
- ind=j
- mat[i].insert(j,d)
- count=1
- break
- else:
- for j in range(y-1,-1,-1):
- if mat[i][j]>d:
- ind=j+1
- mat[i].insert(j+1,d)
- count=1
- break
- if x%2==0:
- mat[x-1].pop(0)
- else:
- mat[x-1].pop(y-1)
- for i in range(x):
- if len(mat[i])!=y and pow(-1,i)==-1:
- mat[i+1].insert(0,mat[i].pop(0))
- if len(mat[i])!=y and pow(-1,i)==1:
- mat[i+1].append(mat[i][len(mat[i])-1])
- mat[i].pop()
- for row in mat:
- for el in row:
- print('{:3}'.format(el),end='')
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement