You are viewing a single comment's thread. Return to all comments →
#include <stdio.h> #include <stdint.h> int main(){ int grid[20][20]; int32_t max=INT_FAST8_MIN,temp=0; for(int grid_i = 0; grid_i < 20; grid_i++){ for(int grid_j = 0; grid_j < 20; grid_j++){ scanf("%d",&grid[grid_i][grid_j]); } } for(int grid_i = 0; grid_i < 20; grid_i++){ for(int grid_j = 0; grid_j < 20; grid_j++){ if (grid_j<=16&&grid_i<=16){ temp=grid[grid_i][grid_j]*grid[grid_i][grid_j+1]*grid[grid_i][grid_j+2]*grid[grid_i][grid_j+3]; if(temp>max)max=temp; temp=grid[grid_i][grid_j]*grid[grid_i+1][grid_j]*grid[grid_i+2][grid_j]*grid[grid_i+3][grid_j]; if(temp>max)max=temp; temp=grid[grid_i][grid_j]*grid[grid_i+1][grid_j+1]*grid[grid_i+2][grid_j+2]*grid[grid_i+3][grid_j+3]; if(temp>max)max=temp; } if(grid_i>=3&&grid_j<=16){ temp=grid[grid_i][grid_j]*grid[grid_i-1][grid_j+1]*grid[grid_i-2][grid_j+2]*grid[grid_i-3][grid_j+3]; if(temp>max)max=temp; } if(grid_i>16&&grid_j<=16){ temp=grid[grid_i][grid_j]*grid[grid_i][grid_j+1]*grid[grid_i][grid_j+2]*grid[grid_i][grid_j+3]; if(temp>max)max=temp; } } } printf("%u",max); return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #11: Largest product in a grid
You are viewing a single comment's thread. Return to all comments →