Euler_8.cpp (590B)
1 #include <fstream> 2 3 #include "Euler.h" 4 5 llui Euler::FindGreatestProductOf13AdjacentDigits() 6 { 7 std::ifstream fin; 8 fin.open("files/p8_digits.txt"); 9 10 std::string number; 11 12 std::getline(fin, number); 13 14 fin.close(); 15 16 llui greatestProduct = 0; 17 18 for (unsigned i = 0; i < number.length() - 13; ++i) 19 { 20 std::vector<int> digits; 21 22 llui temp = 1; 23 24 for (unsigned j = i; j < i + 13; ++j) 25 temp *= (number.at(j) - 48); 26 27 if (temp > greatestProduct) { 28 greatestProduct = temp; 29 } 30 } 31 32 return greatestProduct; 33 }