题解 | #求解立方根#

求解立方根

http://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca

import sys

num = sys.stdin.readline().strip() sign = 1 if num[0] == "-": sign = -1 n = float(num[1:]) else: n = float(num) if n == 0: print(0.0 * sign) if n == 1: print(1.0 * sign) if n > 1: left, right = 1, n if 0 < n < 1: left, right = n, 1 while left < right: mid = (left + right) / 2 res = mid**3 if mid * mid * mid < n: left = mid elif mid * mid * mid > n: right = mid if round(left,1) == round(right,1): print(round(left, 1) * sign) break

全部评论

相关推荐

11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
躺尸修仙中:因为很多92的也去卷中小厂,反正投递简历不要钱,面试不要钱,时间冲突就推,不冲突就面试积累经验
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务