Advertisement
RedstoneHair

07. Snake Moves

Jan 20th, 2023
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. class Grid: # Копирано от infinigrid.py
  2.     width = 2
  3.     height = 2
  4.     length = 4
  5.     array = []
  6.     initiator = None
  7.  
  8.     def __init__(self, width: int, height: int, initiator: any = None):
  9.         self.width = width
  10.         self.height = height
  11.         self.length = width * height
  12.         self.array = [initiator] * self.length
  13.         self.initiator = initiator
  14.  
  15.     def get(self, x: int, y: int):
  16.         if x < 0 or y < 0 or x > self.width - 1 or y > self.height - 1:
  17.             return None
  18.         return self.array[x + (y * self.width)]
  19.  
  20.     def set(self, x: int, y: int, value: any):
  21.         if x < 0 or y < 0 or x > self.width - 1 or y > self.height - 1:
  22.             return
  23.         self.array[x + (y * self.width)] = value
  24.  
  25. height, width = map(int, input().split(' '))
  26. string = input()
  27.  
  28. # height = 5
  29. # width = 6
  30. # string = "SoftUni"
  31.  
  32. grid = Grid(width, height, '-')
  33.  
  34. i = 0
  35.  
  36. for y in range(height):
  37.     if y%2 == 0:
  38.         for x in range(width):
  39.             grid.set(x, y, string[i])
  40.             i += 1
  41.             if i > len(string)-1: i = 0
  42.     else:
  43.         for x in range(width-1, -1, -1):
  44.             grid.set(x, y, string[i])
  45.             i += 1
  46.             if i > len(string)-1: i = 0
  47.  
  48. for y in range(height):
  49.     for x in range(width):
  50.         print(grid.get(x, y), end='')
  51.     print('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement