Професионална програма
Loading...
Zapryan avatar Zapryan 5 Точки

Задача ''Minesweeper Generator''

Здравейте, колеги! Ще бъда много благодарен, ако някой може да ми помогне със следната задача:

Minesweeper Generator
Everybody remembers the old mines game. Now it is time to create your own.

You will be given an integer n for the size of the mines field with square shape and another one for the number of bombs that you have to place in the field. On the next n lines, you will receive the position for each bomb. Your task is to create the game field placing the bombs at the correct positions and mark them with "*", and calculate the numbers in each cell of the field. Each cell represents a number of all bombs directly near it (up, down, left, right and the 4 diagonals).     
                            
 

Input
On the first line, you are given the integer n – the size of the square matrix.
On the second line – the number of the bombs.
The next n lines holds the position of each bomb.
Output
Print the matrix you've created.
Constraints
The size of the square matrix will be between [2…15].

В Judge получавам 87 точки и Runtime error и не мога да разбера какво пропускам.

Моят код е: https://pastebin.com/bHTsB0Jr

Линк към Judge: https://judge.softuni.bg/Contests/Practice/Index/2463#1

 

Тагове:
0
Python Advanced
MartinBG avatar MartinBG 3972 Точки
Best Answer

Решеието не работи за позиции с 2 или повече цифри (редове №33 и 34):

for _ in range(number_bombs):
    tokens = input()
    row = int(tokens[1]) #33
    col = int(tokens[4]) #34
    matrix[row][col] = '*'

Примерен фикс:

for _ in range(number_bombs):
    [row, col] = map(lambda x: int(x), input()[1:][:-1].split(', '))
    matrix[row][col] = '*'

 

0
Zapryan avatar Zapryan 5 Точки

Много благодаря! Аз предполагах, че точно там е проблемът и затова пробвах с регекс преди ти да ми отговориш и получих 100 точки. Твоето решение, обаче ми харесва повече. :)


 
1
Unconsciousness avatar Unconsciousness 0 Точки

Супер , и аз там гърмях,но ползвах .isnumeric , и по същия начин отрязваше двуцифрените :)

А пробвах каквои ли не :)

0