M
M
moriokii2021-11-21 03:01:04
Python
moriokii, 2021-11-21 03:01:04

How to find the coordinates (Picture)?

You need to find the "path" where the line vertically contains the largest number of zeros.
61998c14815dc021345442.png
Find the weakest spot in the wall, # blocks, 0 voids.

It is necessary to find the coordinates of the place where the wall is narrowest. If there are several such places, you need to choose the most important of them and display its index horizontally (the leftmost column has an index of 0). If there are no voids in the wall, print -1.

That is, count how many from one end to zero and somehow skip the lowest ones.
Help please
Also all values ​​need to be adaptive

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
n1ksON, 2021-11-21
@moriokii

s = '##########\n####0##0##\n00##0###00\n0123456789'
sArray = s.split('\n') # делим исходную строку по строкам
arr = [[0 for j in range(len(sArray))] for i in range(len(sArray[0]))] # создаём двумерный массив, где количество элементов в arr = длине 1 строки
countMax = 1 # максимум '0' в столбце
countBMin = len(sArray[0]) # минимум '#' в столбце
column = -1 # столбец
for i in range(len(sArray)):
    for j in range(len(sArray[0])):
        arr[j][i] = sArray[i][j] # создаём массив из массивов столбцов
for i in range(len(arr)):
    count = arr[i].count('0') # считаем кол-во '0' в столбце 
    countB = arr[i].count('#') # считаем кол-во '#' в столбце
    if (count >= countMax and countB < countBMin): # кол-во '0' должно быть наибольшим, а кол-во '#' - наименьшим
        countMax = count
        countBMin = countB
        column = i
print(column)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question