diff --git a/11 - Mayor producto en cuadricula/p11 b/11 - Mayor producto en cuadricula/p11 index 5b50848623fe11843f53240176fb4264b591e9d3..af257bb659cf31878029988ccda05d85a0a0cdbf 100755 GIT binary patch literal 12776 zcmcIq3vgT2nLhW*4@GulI}Q*CG`E4UfnY@sTbA3-p9Qdr#;PEweq$iul?KKnlpYc!do#^1h6coZ~ zK2jq&@^wtik2UuLBiw+a!jCcOkB}pjE(!~IQuK9KNkgUlq9a(@On^7CR_qhMSaj}3TRSH>eP@mL}| z)-vYvws>0|>7>KW{U<)k-OU@ea0!_Y4H(&8h!3qL&Cg$Q_@y_-?)l~TKP-BmExqOX zU%g%RPb4cp7+!SS1I`5%xSyDVPJU_?_?OHSOxq>8dOikEr?e-8o5y2)MohYC!dxCIs{nRmzf0b}@`P3B0A10h!J#~=d_YqE)#;F6qUBBzi zzjcqE|Baq|@9f6Sy+@`F)ccu!B?*R zTc2evDQc^e+8UOS9&Ufv+P4}s#eGJ- zxuUWUNT6_R`>FdNL*v`@htBAAjOAZ?@uNaP&;Q^cfr)SI`kz99Oa165{MYmEe5ij{ zKN2_rgy|Ezr@-~XQ6%R_-{jLr^!(30)c;P;|6b3ZYk1B!n78T^epR2?q#g-OlhB^P zbUtuKp9oCp`M`0Z0>fjc=pxtm1dcWQkgd@&b#iFSCJgQ))9XJg6!Nb@gC0J*2TH=n z^!zdX&9mZ(%O~D-2en@brBM{={6YV<=_L+IT_Ms}KrjJ&E!@zt(pp>kCCz%2Muu zGtCW;twUs#rrZP5z;2*85r>|C?Um=T&b$_;ANf>Nh5pd1R5f>PKTJiGf8f)6_8jtd zc2D5b+>|AEuDRiB&mvl&=EbVg^FM~-v%2!*J%MxjzCHC16W2Z?^Chb~i?QnAhVLD% zsBvQQfRXkYt>1rP1?1;|Eh@Spj5t)j#Je=H=g3#x7vNT7zDfM&kS_JRh z@f26+H6Bkfyyrewco$l*3q@#NvkOHzFuC;kIpHK6^84oeLJemjMZ8mt)4$Wt&;D(zVz`xt4d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|c{)<=qjZX;9t+rG za)`T(;Tsg_3cChqwYVXxMM|B_ToGWM6*i_;RGA|}8)4lQtEO+$E@9ixu2lpq`h0Ch zCM~P6SBVR<3QH&uT++(|)Bg<(3e+L9Bg_02{eFinzXW6T(lM-PV=pmtWx%c%4*lPo zYF1kraOh>@tavNjChSP1-!fe_Z0u5HjfEEra0V|1$zNm9k0_jlbs*}M0sen_4n?tp z9tXSRubF;Q_{8T6&xSz2qE~^4gRKkHSoE&}YQS@WH4?B(z<%vuQq>yEO)+wmvW-w;@6bso*;&n9*xSYs*kYGOiSN6H`h EKW`=K9{>OV diff --git a/11 - Mayor producto en cuadricula/p11.cpp b/11 - Mayor producto en cuadricula/p11.cpp index 5e2ecbb..87b94b4 100644 --- a/11 - Mayor producto en cuadricula/p11.cpp +++ b/11 - Mayor producto en cuadricula/p11.cpp @@ -40,12 +40,21 @@ using namespace std; #define SIZE_Y 20 #define SIZE_MAX_NUMBER 2 +int multiplyHorRight(int x, int y, int grid[SIZE_X][SIZE_Y]); +int multiplyVerDown(int x, int y, int grid[SIZE_X][SIZE_Y]); +int multiplyDiagRight(int x, int y, int grid[SIZE_X][SIZE_Y]); +int multiplyDiagLeft(int x, int y, int grid[SIZE_X][SIZE_Y]); + +int maxValue(int a, int b); + int main(int argc, char const *argv[]) { int x; int y; int grid[SIZE_X][SIZE_Y] = {0}; + long resultMax = 0; + char buffer[SIZE_MAX_NUMBER]; char *ptrBuffer; char *ptrNumeros; @@ -72,25 +81,71 @@ int main(int argc, char const *argv[]) ptrBuffer = buffer; memset(buffer,'\0',SIZE_MAX_NUMBER); - } else { *ptrBuffer++ = *ptrNumeros; } ptrNumeros++; } - //________________________________________- - //PRINT GRID - for (int i = 0; i < SIZE_Y; ++i) + //------------------------------------------ + resultMax = 0; + for (y = 0; y < SIZE_Y; ++y) { - for (int j = 0; j < SIZE_X; ++j) + for (x = 0; x < SIZE_X; ++x) { - printf("%d\t",grid[j][i]); + resultMax = maxValue(multiplyHorRight(y, x, grid), resultMax); //Validacion de Horizontal + resultMax = maxValue(multiplyVerDown(y, x, grid), resultMax); //Validacion de Vertical + resultMax = maxValue(multiplyDiagRight(y, x, grid), resultMax); //Validacion en Diagonal derecha + resultMax = maxValue(multiplyDiagLeft(y, x, grid), resultMax); //Validacion en Diagonal izquierda } - printf("\n"); } - //------------------------------------------ + printf("Resultado:\t%ld\n", resultMax); return 0; +} + + +//HORIZOTAL +int multiplyHorRight(int x, int y, int grid[SIZE_X][SIZE_Y]) +{ + return ( x+3 < SIZE_X ) ? + grid[x][y] * + grid[x+1][y] * + grid[x+2][y] * + grid[x+3][y] : 0; +} + +//VERTICAL +int multiplyVerDown(int x, int y, int grid[SIZE_X][SIZE_Y]) +{ + return ( y+3 < SIZE_Y ) ? + grid[x][y] * + grid[x][y+1] * + grid[x][y+2] * + grid[x][y+3] : 0; +} + +//DIAGONAL +int multiplyDiagRight(int x, int y, int grid[SIZE_X][SIZE_Y]) +{ + return ( x+3 < SIZE_X && y+3 < SIZE_Y ) ? + grid[x][y] * + grid[x+1][y+1] * + grid[x+2][y+2] * + grid[x+3][y+3] : 0; +} + +int multiplyDiagLeft(int x, int y, int grid[SIZE_X][SIZE_Y]) +{ + return ( x-3 >= 0 && y+3 < SIZE_Y ) ? + grid[x][y] * + grid[x-1][y+1] * + grid[x-2][y+2] * + grid[x-3][y+3] : 0; +} + +int maxValue(int a, int b) +{ + return (a >= b) ? a : b; } \ No newline at end of file