Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. x=int(input('input first index of matrix: '))
  2. y=int(input('input second index of matrix: '))
  3. d=int(input('input digit: '))
  4. mat=[[ int(input('input: ')) for j in range(y)][::pow(-1, i)] for i in range(x)]
  5. count=0
  6. for i in range(x):
  7. if count==1:
  8. break
  9. if pow(-1,i)==1:
  10. for j in range(y):
  11. if mat[i][j]>d:
  12. ind=j
  13. mat[i].insert(j,d)
  14. count=1
  15. break
  16. else:
  17. for j in range(y-1,-1,-1):
  18. if mat[i][j]>d:
  19. ind=j+1
  20. mat[i].insert(j+1,d)
  21. count=1
  22. break
  23. if x%2==0:
  24. mat[x-1].pop(0)
  25. else:
  26. mat[x-1].pop(y-1)
  27.  
  28. for i in range(x):
  29. if len(mat[i])!=y and pow(-1,i)==-1:
  30. mat[i+1].insert(0,mat[i].pop(0))
  31. if len(mat[i])!=y and pow(-1,i)==1:
  32. mat[i+1].append(mat[i][len(mat[i])-1])
  33. mat[i].pop()
  34.  
  35. for row in mat:
  36. for el in row:
  37. print('{:3}'.format(el),end='')
  38. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement