ChatCrawlerпоиск по публичному Telegram Открыть приложение
О

Основы Python

сообщение · 2025-04-29 12:50 UTC
R
Ответсообщение недоступно
from itertools import product f = input() f = f.replace('(', '( ').replace(')', ' )') op = ['(', ')', 'not', 'and', 'or', '^', '->', '~'] ar = f.split() stack = [] solve = [] di = {} for i in f: if i.isupper(): di[i] = 0 di = dict(sorted(di.items())) f = 0 for i in ar: if i.isupper(): solve.append(i) elif len(stack) == 0: stack.append(i) else: if i == ')': while stack[-1] != '(': solve.append(stack.pop(-1)) if stack[-1] == '(': del stack[-1] else: if op.index(i) < op.index(stack[-1]): stack.append(i) else: while len(stack) != 0 and stack[-1] != '(' and op.index(i) > op.index(stack[-1]): solve.append(stack.pop(-1)) stack.append(i) while len(stack) != 0: solve.append(stack.pop(-1)) res = [] for i in range(len(solve)): if solve[i].isupper(): res.append(solve[i]) else: if solve[i] == 'not': res[-1] = 'not(' + res[-1] + ')' elif solve[i] == 'and': a = res.pop(-1) b = res.pop(-1) res.append(f'({b}) and ({a})') elif solve[i] == 'or': a = res.pop(-1) b = res.pop(-1) res.append(f'({b}) or ({a})') elif solve[i] == '^': a = res.pop(-1) b = res.pop(-1) res.append(f'(({b}) or ({a})) % 2') elif solve[i] == '->': a = res.pop(-1) b = res.pop(-1) res.append(f'not({b}) or ({a})') elif solve[i] == '~': a = res.pop(-1) b = res.pop(-1) res.append(f'({b}) == ({a})') res_1 = res[0] var = [i for i in product([0, 1], repeat=len(di))] for i in di: print(i, end=' ') print('F') for i in var: index = 0 for j in di: di[j] = i[index] index += 1 for j in di: print(di[j], end=' ') print(int(eval(res_1, {}, di))) решил на досуге последнюю задачу, но 5 тест не проходит из-за неправильного ответа, у кого-то есть варианты почему?

Вся лента · оригинал в Telegram

Открыть в Telegram Каталог площадок Искать в ChatCrawler

Слепок открытой публичной ленты из поискового индекса ChatCrawler — «Google по публичному Telegram»; обновляется по мере обхода площадки. Время — UTC.

Только публичный контент, официальный API Telegram. О проекте · Вопросы · Чего мы не делаем · Убрать страницу из выдачи · Каталог