c++ - Project Euler Problem #11 -


Source:

Quick Overview: Take 20x20 grid of numbers and calculate the largest product of 4 pairs Make either the number of numbers in horizontal, vertical or diagonal.

My current approach is to split the 20x20 grid into single rows and single columns and go there with a more manageable grid. The code I am using to divide rows in rows is

  zero fillrows (string :: const_iterator & fieldIter, list> int> and rowElements, vector & lt ; List & lt; int & gt; & gt; Rows) {// field has already been started Integer number (0); (; FieldEeter & lt; field.end); ++ field-maker) {ifdigit (field [* field era])) {rowElements.push_back (toInt (field [* field etter]); ++ count; } If (count == 40) {rows.push_back (rowElements); Calculation = 0; RowElements.clear (); Short description: I have the field set as the  static const std :: string field  and I am filling a vector with the lists of rows. Why a list? Since there is no clear work in the queue, practice STL using the container lists and not the ones I write myself. 

However, this thing is not working. Often I think that it excludes one character (constructs function toInt as integer) and I end up with 18 rows, two rows less than 20x20 grid looks good on the length of the rows.

Rows: 18

Rowliment [0]: 40 (Instead of adding i, each number is saved individually . Will be OK later)

What am I doing wrong?

You know that the grid is 20x20, so paste it into a text file and read it like You will usually read a matrix:

 for  (for int i = 0; i  

Then clarify: For each element [i] [j] , 4 elements are down, 4 to right, 4 overlapped and 4 left side Find more products if you can not get 4 elements due to borders, then ignore those people you can get.

There is no need to do this as you are doing it to keep it simple because it is a simple problem, and if you eliminate it then you will only make your life difficult.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -