Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exercesis_Multidimensional_list_2
- # Flatten_list
- line = input().split("|")
- sub_lists = []
- for sub_string in line[::-1]:
- sub_lists.extend(sub_string.split())
- print(*sub_lists)
- # Knight_game
- size = int(input())
- matrix = [list(input()) for _ in range(size)]
- positions = (
- (-2, -1), # up 2, left 1
- (-2, 1), # up 2, right 1
- (-1, -2), # up 1, left 2
- (-1, 2),
- (2, 1),
- (2, -1),
- (1, 2),
- (1, -2)
- )
- removed_knights = 0
- while True:
- max_attacks = 0
- knight_with_most_attack_pos = []
- for row in range(size):
- for col in range(size):
- if matrix[row][col] == "K":
- attacks = 0
- for pos in positions:
- pos_row = row + pos[0]
- pos_col = col + pos[1]
- if 0 <= pos_row < size and 0 <= pos_col < size:
- if matrix[pos_row][pos_col] == "K":
- attacks += 1
- if attacks > max_attacks:
- knight_with_most_attack_pos = [row, col]
- max_attacks = attacks
- if knight_with_most_attack_pos:
- matrix[knight_with_most_attack_pos[0]][knight_with_most_attack_pos[1]] = "0" # Махаме коня
- removed_knights += 1
- else:
- break
- print(removed_knights)
- # Matrix_modification
- size = int(input())
- matrix = [[int(x) for x in input().split()] for _ in range(size)]
- command = input().split()
- while command[0] != "END":
- type_command, row, col, value = command[0], int(command[1]), int(command[2]), int(command[3])
- if not (0 <= row < size and 0 <= col < size):
- print("Invalid coordinates")
- elif type_command == "Add":
- matrix[row][col] += value
- elif type_command == "Subtrack":
- matrix[row][col] -= value
- command = input().split()
- [print(*row) for row in matrix]
- # Presents_delivery
- def eat_cookie(presents_left, nice_kids):
- for coordinates in directions.values():
- r = santa_pos[0] + coordinates[0]
- c = santa_pos[1] + coordinates[1]
- if neighborhood[r][c].isalpha():
- if neighborhood[r][c] == "V":
- nice_kids += 1
- neighborhood[r][c] = '-'
- presents_left -= 1
- if not presents_left:
- break
- return presents_left, nice_kids
- presents = int(input())
- size = int(input())
- neighborhood = []
- santa_pos = []
- total_nice_kids = 0
- nice_kids_visited = 0
- directions = {
- 'up': (-1, 0),
- 'down': (1, 0),
- 'left': (0, -1),
- 'right': (0, 1)
- }
- for row in range(size):
- line = input().split()
- neighborhood.append(line)
- if "S" in line:
- santa_pos = [row, line.index("S")]
- neighborhood[row][santa_pos[1]] = '-'
- total_nice_kids += line.count("V")
- command = input()
- while command != " Christmas morning":
- santa_pos = [
- santa_pos[0] + directions[command][0],
- santa_pos[1] + directions[command][1],
- ]
- house = neighborhood[santa_pos[0]][santa_pos[1]]
- if house == "V":
- nice_kids_visited += 1
- presents -= 1
- elif house == "C":
- presents, nice_kids_visited = eat_cookie(presents, nice_kids_visited)
- neighborhood[santa_pos[0]][santa_pos[1]] = '-'
- if not presents or nice_kids_visited == total_nice_kids:
- command = input()
- neighborhood[santa_pos[0]][santa_pos[1]] = "S"
- if not presents and nice_kids_visited < total_nice_kids:
- print("Santa ran out of presents!")
- print(*[" ".join(line) for line in neighborhood], sep="\n")
- if total_nice_kids == nice_kids_visited:
- print(f"Good job, Santa! {total_nice_kids} happy nice kid/s.")
- else:
- print(f"No presents for {kkkkkkk} nice kid/s.")
- # Range_day
- def move(directoin: str, steps: int):
- r = my_position[0] + (directions[directoin][0] * steps)
- c = my_position[1] + (directions[directoin][1] * steps)
- if not (0 <= r < SIZE and 0 <= c < SIZE):
- return my_position
- if field[r][c] == 'x':
- return my_position
- return [r, c]
- def shoot(direction):
- r = my_position[0] + directions[direction][0]
- c = my_position[1] + directions[direction][1]
- while 0 <= r < SIZE and 0 <= c < SIZE:
- if field[r][c] == 'x':
- field[r][c] = '.'
- return [r, c]
- r += directions[direction][0]
- c += directions[direction][1]
- SIZE = 5
- field = []
- targets = 0
- targets_hit = 0
- target_hit_positions = []
- my_position = []
- directions = {
- 'up': (-1, 0),
- 'down': (1, 0),
- 'left': (0, -1),
- 'right': (0, 1)
- }
- for row in range(SIZE):
- field.append((input().split()))
- if 'A' in field[row]:
- my_position = [row, field[row].index('A')]
- targets += field[row].count('x')
- for _ in range(int(input())):
- command_info = input().split()
- if command_info[0] == 'move':
- my_position = move(command_info[1], int(command_info[2]))
- elif command_info[0] == 'shoot':
- targets_down_pos = shoot(command_info[1])
- if targets_down_pos:
- target_hit_positions.append(targets_down_pos)
- targets_hit += 1
- if targets_hit == targets:
- print(f"Training completed! All {targets} targets hit.")
- else:
- print(f"Training not completed! { targets - targets_hit} targets left.")
- print(*target_hit_positions, sep="\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement