Commit da9921201cc6f84e938b7d92fd763ab3dfd1a8d2
1 parent
20676b739a
Exists in
master
p11 - Resuelto
Showing
2 changed files
with
63 additions
and
8 deletions
Show diff stats
11 - Mayor producto en cuadricula/p11
No preview for this file type
11 - Mayor producto en cuadricula/p11.cpp
... | ... | @@ -40,12 +40,21 @@ using namespace std; |
40 | 40 | #define SIZE_Y 20 |
41 | 41 | #define SIZE_MAX_NUMBER 2 |
42 | 42 | |
43 | +int multiplyHorRight(int x, int y, int grid[SIZE_X][SIZE_Y]); | |
44 | +int multiplyVerDown(int x, int y, int grid[SIZE_X][SIZE_Y]); | |
45 | +int multiplyDiagRight(int x, int y, int grid[SIZE_X][SIZE_Y]); | |
46 | +int multiplyDiagLeft(int x, int y, int grid[SIZE_X][SIZE_Y]); | |
47 | + | |
48 | +int maxValue(int a, int b); | |
49 | + | |
43 | 50 | int main(int argc, char const *argv[]) |
44 | 51 | { |
45 | 52 | int x; |
46 | 53 | int y; |
47 | 54 | int grid[SIZE_X][SIZE_Y] = {0}; |
48 | 55 | |
56 | + long resultMax = 0; | |
57 | + | |
49 | 58 | char buffer[SIZE_MAX_NUMBER]; |
50 | 59 | char *ptrBuffer; |
51 | 60 | char *ptrNumeros; |
... | ... | @@ -72,25 +81,71 @@ int main(int argc, char const *argv[]) |
72 | 81 | |
73 | 82 | ptrBuffer = buffer; |
74 | 83 | memset(buffer,'\0',SIZE_MAX_NUMBER); |
75 | - | |
76 | 84 | } |
77 | 85 | else { *ptrBuffer++ = *ptrNumeros; } |
78 | 86 | |
79 | 87 | ptrNumeros++; |
80 | 88 | } |
81 | 89 | |
82 | - //________________________________________- | |
83 | - //PRINT GRID | |
84 | - for (int i = 0; i < SIZE_Y; ++i) | |
90 | + //------------------------------------------ | |
91 | + resultMax = 0; | |
92 | + for (y = 0; y < SIZE_Y; ++y) | |
85 | 93 | { |
86 | - for (int j = 0; j < SIZE_X; ++j) | |
94 | + for (x = 0; x < SIZE_X; ++x) | |
87 | 95 | { |
88 | - printf("%d\t",grid[j][i]); | |
96 | + resultMax = maxValue(multiplyHorRight(y, x, grid), resultMax); //Validacion de Horizontal | |
97 | + resultMax = maxValue(multiplyVerDown(y, x, grid), resultMax); //Validacion de Vertical | |
98 | + resultMax = maxValue(multiplyDiagRight(y, x, grid), resultMax); //Validacion en Diagonal derecha | |
99 | + resultMax = maxValue(multiplyDiagLeft(y, x, grid), resultMax); //Validacion en Diagonal izquierda | |
89 | 100 | } |
90 | - printf("\n"); | |
91 | 101 | } |
92 | - //------------------------------------------ | |
93 | 102 | |
103 | + printf("Resultado:\t%ld\n", resultMax); | |
94 | 104 | |
95 | 105 | return 0; |
106 | +} | |
107 | + | |
108 | + | |
109 | +//HORIZOTAL | |
110 | +int multiplyHorRight(int x, int y, int grid[SIZE_X][SIZE_Y]) | |
111 | +{ | |
112 | + return ( x+3 < SIZE_X ) ? | |
113 | + grid[x][y] * | |
114 | + grid[x+1][y] * | |
115 | + grid[x+2][y] * | |
116 | + grid[x+3][y] : 0; | |
117 | +} | |
118 | + | |
119 | +//VERTICAL | |
120 | +int multiplyVerDown(int x, int y, int grid[SIZE_X][SIZE_Y]) | |
121 | +{ | |
122 | + return ( y+3 < SIZE_Y ) ? | |
123 | + grid[x][y] * | |
124 | + grid[x][y+1] * | |
125 | + grid[x][y+2] * | |
126 | + grid[x][y+3] : 0; | |
127 | +} | |
128 | + | |
129 | +//DIAGONAL | |
130 | +int multiplyDiagRight(int x, int y, int grid[SIZE_X][SIZE_Y]) | |
131 | +{ | |
132 | + return ( x+3 < SIZE_X && y+3 < SIZE_Y ) ? | |
133 | + grid[x][y] * | |
134 | + grid[x+1][y+1] * | |
135 | + grid[x+2][y+2] * | |
136 | + grid[x+3][y+3] : 0; | |
137 | +} | |
138 | + | |
139 | +int multiplyDiagLeft(int x, int y, int grid[SIZE_X][SIZE_Y]) | |
140 | +{ | |
141 | + return ( x-3 >= 0 && y+3 < SIZE_Y ) ? | |
142 | + grid[x][y] * | |
143 | + grid[x-1][y+1] * | |
144 | + grid[x-2][y+2] * | |
145 | + grid[x-3][y+3] : 0; | |
146 | +} | |
147 | + | |
148 | +int maxValue(int a, int b) | |
149 | +{ | |
150 | + return (a >= b) ? a : b; | |
96 | 151 | } |
97 | 152 | \ No newline at end of file | ... | ... |