#include <iostream>
#include <vector>
using namespace std;
class Box
{
public:
int ID;
bool west, east;
Box(int id)
{
ID = id;
west = rand() % 2;
east = rand() % 2;
}
};
int main()
{
vector<Box> box;
Box box1(1);
box.push_back(box1);
Box box2(2);
box.push_back(box2);
Box box3(3);
box.push_back(box3);
Box box4(4);
box.push_back(box4);
Box box5(5);
box.push_back(box5);
Box box6(6);
box.push_back(box6);
Box box7(7);
box.push_back(box7);
Box box8(8);
box.push_back(box8);
for (int i = 0; i < 8; i++)
{
if (box[i].west)
cout << ":";
else
cout << "|";
cout << i + 1;
if (box[i].east)
cout << ":";
else
cout << "|";
}
int num = 0;
int count = 0;
for (int i = 0; i < 8; i++)
{
int m = i;
int n = i;
int mi = 0, ni = 0;
while (true)
{
if (m < 8)
{
if (box[m].east == true)
{
m++;
mi++;
}
else
{
break;
}
}
else
break;
}
while (true)
{
if ((n >= 0))
{
if (box[n].west == true)
{
n--;
ni++;
}
else
{
break;
}
}
else
break;
}
if (ni + mi > count)
{
num = i;
count = ni + mi;
}
}
vector<int> rooms;
int ma = num, na = num;
while (true)
{
if (ma < 8)
{
if (box[ma].east == true)
{
ma++;
rooms.push_back(ma);
}
else
{
break;
}
}
else
break;
}
while (true)
{
if ((na >= 0))
{
if (box[na].west == true)
{
na--;
rooms.push_back(na);
}
else
{
break;
}
}
else
break;
}
cout << "\n The box with maximum reachability is box " << num << " where you can reach ";
int s = rooms.size();
for (int i = 0; i < s; i++)
cout << i + 1 << ",";
}
Comments
Leave a comment