1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
int main()
{
const int inventorySlotRows = 5;
const int inventorySlotColumns = 5;
int arr[inventorySlotRows][inventorySlotColumns] =
{
{ 1, 1, 1, 1, 1 },
{ 0, 1, 1, 0, 1 },
{ 1, 0, 1, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 }
};
// needed empty slots for new item
int emptySlotsRows = 4;
int emptySlotsColumns = 2;
bool have = false;
for(int i = 0; i < inventorySlotRows; ++i)
{
for(int j = 0; j < inventorySlotColumns; ++j)
{
if(0 == arr[i][j] && (i + emptySlotsRows) <= inventorySlotRows && (j + emptySlotsColumns) <= inventorySlotColumns)
{
int sum = 0;
for(int k = 0; k < emptySlotsRows; ++k)
{
for(int l = 0; l < emptySlotsColumns; ++l)
{
sum += arr[i+k][j+l];
}
}
have = (sum == 0) ? true : false;
}
}
}
std::cout << std::boolalpha << have << std::endl;
return 0;
};
|