欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

2020牛客暑期多校训练营(第九场)A.Groundhog and 2-Power Representation

程序员文章站 2022-06-22 23:08:08
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 222. For example:137=27+23+20137=2^7+2^3+2^0137=27+23+20.And powe...

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 22. For example:137=27+23+20137=2^7+2^3+2^0.

And powers are expressed in parentheses.That is ,a(b){a(b)} stands for ab{a^b}.Therefore,137137 can be expressed as 137=2(7)+2(3)+2(0)137={2(7)+2(3)+2(0)}.

Further more,for 7=22+2+207=2^2+2+2^0 is expressed with 2{2}3=2+203=2+2^0,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)}.

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}+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).

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

熟悉 pythonpython 的都知道 pythonpython 有个 evaleval 函数可以直接求表达式的值,那么我们只需要把 (( 替换成 (**( 即可,因为在 python 中 2x2**x 代表 xx 幂,AC代码如下:

print(eval(input().replace('(','**(')))

本文地址:https://blog.csdn.net/qq_43765333/article/details/107884328

相关标签: python 牛客