博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Largest product in a series
阅读量:7231 次
发布时间:2019-06-29

本文共 2428 字,大约阅读时间需要 8 分钟。

这个我开始理解错了,算错了。

我以为是求连续5个数的最大值,结果,是连接5个数相乘的最大值。

英语不好,容易吃亏啊。

Find the greatest product of five consecutive digits in the 1000-digit number。

73167176531330624919225119674426574742355349194934

96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

代码:

str = "\73167176531330624919225119674426574742355349194934\96983520312774506326239578318016984801869478851843\85861560789112949495459501737958331952853208805511\12540698747158523863050715693290963295227443043557\66896648950445244523161731856403098711121722383113\62229893423380308135336276614282806444486645238749\30358907296290491560440772390713810515859307960866\70172427121883998797908792274921901699720888093776\65727333001053367881220235421809751254540594752243\52584907711670556013604839586446706324415722155397\53697817977846174064955149290862569321978468622482\83972241375657056057490261407972968652414535100474\82166370484403199890008895243450658541227588666881\16427171479924442928230863465674813919123162824586\17866458359124566529476545682848912883142607690042\24219022671055626321111109370544217506941658960408\07198403850962455444362981230987879927244284909188\84580156166097919133875499200524063689912560717606\05886116467109405077541002256983155200055935729725\71636269561882670428252483600823257530420752963450\"print strmax = 0cur = 0for i in xrange(1,len(str)-4):    cur = int(str[i])*int(str[i+1])*int(str[i+2])*int(str[i+3])*int(str[i+4])    if cur > max:        max = cur        print str[i],str[i+1],str[i+2],str[i+3],str[i+4]        print max

 

转载地址:http://kopfm.baihongyu.com/

你可能感兴趣的文章
Bootstrap的使用
查看>>
python设置文字输出颜色
查看>>
WARNING:tornado.access:403 GET /websocket (::1) 1.00ms
查看>>
cocos creator游戏适配这事
查看>>
AngularJS - contorller app module
查看>>
CF666E. Forensic Examination
查看>>
apue第16章笔记
查看>>
Nvidia Driver
查看>>
NIO 相关解析
查看>>
Loj #2304. 「NOI2017」泳池
查看>>
面试技巧,如何通过索引说数据库优化能力,内容来自Java web轻量级开发面试教程...
查看>>
Python实现:某个用户登录后,查看自己拥有所有权限
查看>>
iOS微信朋友圈 评论点击姓名功能
查看>>
Servlet和模本办法
查看>>
static和final修饰方法
查看>>
读《认知三部曲》
查看>>
关于SVN 目录结构
查看>>
tp5页面输出时,搜索后跳转下一页的处理
查看>>
crontab命令
查看>>
面试问题
查看>>