题目链接
Groundhog took a math class. In this class, his math teacher said:
Any positive integer can be represented by the power of 2 2 2. For example: 137 = 2 7 + 2 3 + 2 0 137=2^7+2^3+2^0 137=27+23+20.
And powers are expressed in parentheses.That is , a ( b ) {a(b)} a(b) stands for a b {a^b} ab.Therefore, 137 137 137 can be expressed as 137 = 2 ( 7 ) + 2 ( 3 ) + 2 ( 0 ) 137={2(7)+2(3)+2(0)} 137=2(7)+2(3)+2(0).
Further more,for 7 = 2 2 + 2 + 2 0 7=2^2+2+2^0 7=22+2+20 is expressed with 2 {2} 2, 3 = 2 + 2 0 3=2+2^0 3=2+20,137 can be finally expressed as 137 = 2 ( 2 ( 2 ) + 2 + 2 ( 0 ) ) + 2 ( 2 + 2 ( 0 ) ) + 2 ( 0 ) {137=2(2(2)+2+2(0))+2(2+2(0))+2(0)} 137=2(2(2)+2+2(0))+2(2+2(0))+2(0).
Another example: 1315 = 2 10 + 2 8 + 2 5 + 2 + 1 = 2 ( 2 ( 2 + 2 ( 0 ) ) + 2 ) + 2 ( 2 ( 2 + 2 ( 0 ) ) ) + 2 ( 2 ( 2 ) + 2 ( 0 ) ) + 2 + 2 ( 0 ) 1315=2^{10}+2^8+2^5+2+1 = 2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0) 1315=210+28+25+2+1=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0).
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.
2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
1315
熟悉 p y t h o n python python 的都知道 p y t h o n python python 有个 e v a l eval eval 函数可以直接求表达式的值,那么我们只需要把 ( ( ( 替换成 ∗ ∗ ( **( ∗∗( 即可,因为在 python 中 2 ∗ ∗ x 2**x 2∗∗x 代表 x x x 幂,AC代码如下:
print(eval(input().replace('(','**(')))