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('(','**(')))
牛客暑期多校训练营题解 文章被收录于专栏

收集牛客暑期多校训练营的题解

全部评论

相关推荐

11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
牛客717484937号:双飞硕没实习挺要命的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务