Advertisement
GeorgiLukanov87

07. Snake - Moves Multidimensional Lists - Exercise 1

Aug 27th, 2022 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #  07. Snake Moves
  2.  
  3. # Multidimensional Lists - Exercise 1
  4. #  https://judge.softuni.org/Contests/Practice/Index/1835#6
  5.  
  6.  
  7. from collections import deque
  8.  
  9. size = input().split()
  10. n = int(size[0])
  11. m = int(size[1])
  12.  
  13. word = input()
  14. snake = deque(word)
  15. matrix = []
  16.  
  17. for row in range(n):
  18.     matrix.append([])
  19.     for col in range(m):
  20.         letter_to_add = snake.popleft()
  21.         matrix[row].append(letter_to_add)
  22.         if not snake:
  23.             snake = deque(word)
  24.  
  25. counter = 0
  26. for sub_matrix in matrix:
  27.     if counter % 2 == 0:
  28.         print(''.join(sub_matrix))
  29.     else:
  30.         print(''.join(sub_matrix[::-1]))
  31.  
  32.     counter += 1
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement