【牛客】5674 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 2{2}2. For example:137=27+23+20137=27+23+2^0137=27+23+20.

And powers are expressed in parentheses.That is ,a(b){a(b)}a(b) stands for ab{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=22+2+207=22+2+207=22+2+20(212^121is expressed with 2{2}2),3=2+203=2+2^03=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=210+28+25+2+1=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)1315=2{10}+28+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}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

备注:

The range of answers :[10,10^{180}],and the length of the input data shall not exceed 20000.

题解

Python牛逼!

代码

a = input()
a = a.replace("(","**(")
print(eval(a))

你可能感兴趣的:(【牛客】5674 A-Groundhog and 2-Power Representation)