1+ /*
2+ *
3+ * Solution to Problem 8 (https://projecteuler.net/problem=8) of Project Euler
4+ * Copyright (C) 2017 Arnav Borborah
5+ *
6+ * This program is free software: you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation, either version 3 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ *
19+ */
20+
21+ #include < iostream>
22+ #include < string>
23+
24+ int main ()
25+ {
26+ const std::string numberString = " 73167176531330624919225119674426574742355349194934"
27+ " 96983520312774506326239578318016984801869478851843"
28+ " 85861560789112949495459501737958331952853208805511"
29+ " 12540698747158523863050715693290963295227443043557"
30+ " 66896648950445244523161731856403098711121722383113"
31+ " 62229893423380308135336276614282806444486645238749"
32+ " 30358907296290491560440772390713810515859307960866"
33+ " 70172427121883998797908792274921901699720888093776"
34+ " 65727333001053367881220235421809751254540594752243"
35+ " 52584907711670556013604839586446706324415722155397"
36+ " 53697817977846174064955149290862569321978468622482"
37+ " 83972241375657056057490261407972968652414535100474"
38+ " 82166370484403199890008895243450658541227588666881"
39+ " 16427171479924442928230863465674813919123162824586"
40+ " 17866458359124566529476545682848912883142607690042"
41+ " 24219022671055626321111109370544217506941658960408"
42+ " 07198403850962455444362981230987879927244284909188"
43+ " 84580156166097919133875499200524063689912560717606"
44+ " 05886116467109405077541002256983155200055935729725"
45+ " 71636269561882670428252483600823257530420752963450" ;
46+
47+ long long int greatestProduct = 1 ;
48+
49+ for (std::size_t i = 0 ; i < numberString.length () - 13 ; ++i)
50+ {
51+ long long int currentProduct = 1 ;
52+
53+ for (std::size_t j = i; j < i + 13 ; ++j)
54+ {
55+ currentProduct *= numberString[j] - ' 0' ; // Convert to integer
56+ }
57+
58+ if (currentProduct > greatestProduct)
59+ {
60+ greatestProduct = currentProduct;
61+ }
62+ }
63+
64+ std::cout << greatestProduct << " \n " ;
65+ }
0 commit comments