2020牛客暑期多校训练营(第九场)A
Groundhog and 2-Power Representation
https://ac.nowcoder.com/acm/contest/5674/A
题目描述
Groundhog took a math class. In this class, his math teacher said, any positive integer can be represented by the power of . For example, .
And powers are expressed in parentheses. That is, stands for . Therefore, can be expressed as .
Further more,for is expressed with , ,137 can be finally expressed as .
Another example, .
Groundhog feels amazing and wants you to write a program to simulate the above content. You need to read in an expression that is a power of and calculate its value.
输入描述
Given a string, indicating the power representation.
输出描述
Output the original number.
示例1
输入
2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
输出
1315
备注
The range of answers is ,and the length of the input data shall not exceed .
分析
题面的本质是定义了一个表达式,然后计算表达式的值;而众所周知, 的 函数可以直接输出表达式的值。
题中定义 为 ,而 中认为 为 。因此,只需要将表达式中的 替换为 ,就能用 函数计算表达式的值。
代码
"""*************************************************** Copyright: 11D_Beyonder All Rights Reserved Author: 11D_Beyonder Problem ID: 2020牛客暑期多校训练营(第九场) Problem A Date: 9/3/2020 Description: The Basis Of Python ***************************************************""" print(eval(input().replace('(','**(')))
收集牛客暑期多校训练营的题解