package com.shui.mu.yao.io.algorithm;
/**
*
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
* @author shuimuqinghua77 @date 2011-11-3下午12:37:01
*/
public class Problem8 {
public static int find(String digitStr) {
int max = 0;
char[] digit = digitStr.toCharArray();
for (int i = 0; i < digit.length - 4; i++) {
int temp = 1;
for (int j = i; j < i + 5; j++) {
temp *= digit[j] - '0';
}
if (temp > max)
max = temp;
}
return max;
}
public static void main(String[] args) {
String str = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";
String[] strs = str.split("0");
int max = 0;
for (String digit : strs) {
int t = find(digit);
if (t > max)
max = t;
}
System.out.println(max);
}
}
分享到:
相关推荐
8. MRBT related problem 7 9. USSD related problem 7 10. Announcement problem 7 11. Echo canceller (ECP) problem 8 12. DTI problem 8 13. Group Switch problem 8 14. IN problem 9 15. ONE WAY SPEECH 9 16...
8. Today, Ethernet most commonly runs over twisted-pair copper wire. It also can run over fibers optic links. 9. Dial up modems: up to 56 Kbps, bandwidth is dedicated; ADSL: up to 24 Mbps downstream ...
Chapter 8. Using Computers to Solve Problems Part 3 Software Tools Supporting Program Execution Chapter 9. Computer Process Manipulation by Programs Chapter 10. Memory Management System Chapter 11. I...
Problem Solving with C++, Global Edition by Walter Savitch (author) (Author) Pages:1117 出版社: Pearson Education Limited; 10th edition edition (November 20, 2017) Language: English ISBN-10: ...
### Wicked Problem与Wicked Environmental Problem #### 一、引言 "Wicked Problem"(棘手问题)这一概念最初由霍恩(Horst Rittel)和韦伯(Melvin Webber)于1973年提出,指的是那些复杂且难以解决的问题。这类...
node-problem-detector 镜像包 v0.8.7 版本
MCM 2012年 problem A problem B problem C 枪手论文
8. 查找表结构:DESC 语句(Problem 8) DESC 语句用于显示表的结构信息,例如 DESC emp; 9. 获取最后一句 SELECT 查询到的总行数:FOUND_ROWS() 函数(Problem 9) FOUND_ROWS() 函数用于获取最后一句 SELECT ...
Problem Arrangement zoj 3777
标题 "problem" 提供的信息较少,但从描述中的 "NULL 博文链接:https://eric0000.iteye.com/blog/322311" 可以推测,这可能是一个关于解决某个问题或者技术讨论的博客文章链接。由于没有具体的博文内容,我们无法...
Problem Solving with C++(9th) 英文无水印pdf 第9版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请...
算法设计里关于taxi problem的C语言代码
**Problem 8**:问题涉及到数据预处理,可能是在处理某些特定分布的数据,比如均匀分布,通过转换使其适应某种算法。 **Problem 9**:提到的正确率和错误预测可能与分类算法的性能评估相关,如二分类问题中的真正例...
"Problem_C_Data.zip" 是一个压缩包文件,包含2020年美国数学建模竞赛(简称美赛)C题的题目及相应的原始数据。美赛是一项国际性的数学建模竞赛,每年吸引众多学生参与,旨在提升参赛者的数学、数据分析和解决实际...
HDOJ Problem 1001 C++版
在这个特定的问题“master page search problem”中,我们可能遇到的是在使用Master Page时搜索功能出现的问题。ViewData是ASP.NET MVC框架中的一个特性,用于在控制器和视图之间传递数据,而JavaScript则是客户端...
在操作系统课程中,"机器问题"(Machine Problem)通常指的是与计算机硬件、系统架构以及操作系统内核相关的复杂问题。这些问题涉及到资源管理、并发控制、进程调度、内存分配等多个核心概念,是理解操作系统工作...
8. **Problem 8: 最大数字乘积** - 知识点:字符串处理,数组操作,乘法运算。 - 解决方法:将数字字符串分隔成数组,然后寻找四个数字的最大乘积。 9. **Problem 9: Pythagorean triplet** - 知识点:勾股定理...
flow shop problem GA算法 详细代码标注
**Problem Statement:** Determine the behavior of the function \(f(x) = \frac{x^3 + 8x^2 - 4}{x^2 - 4}\) as \(x \rightarrow 2\). - **Concepts Involved:** Limits, vertical asymptotes. - **Solution ...