Berislave, ja sam to uradio ekstenzivnom metodom da pokažem svoj raskošan talenat :)))
Ma ja sam bio prezadovoljan da sam uošte uspeo da rešim. Kako god.
Da, ta provera prethodnog slova mi je trebala, ali nisam znao kako.
Sad imam mustru.
Hvala na analizi i primerima.
Sačuvaću i proučiću, da nešto novo naučim.
To što kažeš na početku jeste vrlo važno.
Ja kad vidim zadatak, odmah krenem da kucam kod i da testiram u terminalu.
A trebalo bi prvo da napravim to što zovu pseudo kod, tj. recept, pa tek onda
da krenem da kuvam.
I tu dolazim do
zadatka 45: Ukloni nepar zagrade
koji mi izgleda komplikovan, jer ne vidim jasan recept, ni kratak ni dugačak.
Prvo što mi pada na pamet je da prebrojim zagrade i stavim u rečnik.
Onda vidim kojih ima nepar, pa te uklonim. Ali nisam siguran da će to baš da radi.
Moram probati. Zavisi valjda od primera.
# Your task is to restore the balance of open and closed brackets by removing unnecessary ones,
# while trying to use the minimum number of deletions.
# Only 3 types of brackets (), [] and {} can be used in the given string.
# Only a parenthesis can close a parenthesis. That is. in this expression "(}" - the brackets
# aren’t balanced. In an empty string, i.e., in a string that doesn’t contain any brackets
# - the brackets are balanced, but removing all of the brackets isn’t considered to be an
# optimal solution.
# If there are more than one correct answer, then you should choose the one where the character
# that can be removed is closer to the beginning. For example, in this case "[(])", the correct
# answer will be "()", since the removable brackets are closer to the beginning of the line.
# Input: A string of characters () {} []
# Output: A string of characters () {} []
Code:
def remove_brackets(a):
# your code here
return None
if __name__ == '__main__':
print("Example:")
print(remove_brackets('(()()'))
# These "asserts" are used for self-checking and not for an auto-testing
assert remove_brackets('(()()') == '()()'
assert remove_brackets('[][[[') == '[]'
assert remove_brackets('[[(}]]') == '[[]]'
assert remove_brackets('[[{}()]]') == '[[{}()]]'
assert remove_brackets('[[[[[[') == ''
assert remove_brackets('[[[[}') == ''
assert remove_brackets('') == ''
print("Coding complete? Click 'Check' to earn cool rewards!")