2020牛客暑期多校训练营(第九场)A.Groundhog and 2-Power Representation
题目链接
题目描述
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 {2}2 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
熟悉 的都知道 有个 函数可以直接求表达式的值,那么我们只需要把 替换成 即可,因为在 python 中 代表 幂,AC代码如下:
print(eval(input().replace('(','**(')))