Skip to content

20555: evaluate

http://cs101.openjudge.cn/practice/20555/

逻辑表达式求值

输入

一行空格隔开的字串

输出

1(True)或是0(False)

样例输入

( not ( True or False ) ) and ( False or True and True )

样例输出

0
python
def evaluate_expression(expression):
    # Replace logical operators with Python equivalents
    expression = expression.replace("not", "not ").replace("and", " and ").replace("or", " or ")
    # Evaluate the expression
    return int(eval(expression))

# 读取输入并处理
expression = input()
print(evaluate_expression(expression))