#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
class Elevator {
public:
Elevator(int numFloors) : currentFloor(0), numFloors(numFloors) {}
void request(int floor) {
if (floor < 0 || floor >= numFloors) {
std::cerr << "Invalid floor request.\n";
return;
}
if (floor != currentFloor) {
requests.push(floor);
}
}
void operate() {
while (!requests.empty()) {
int targetFloor = requests.front();
requests.pop();
moveToFloor(targetFloor);
}
}
private:
int currentFloor;
int numFloors;
std::queue<int> requests;
void moveToFloor(int targetFloor) {
std::cout << "Moving from floor " << currentFloor << " to floor " << targetFloor << "\n";
currentFloor = targetFloor;
}
};
int main() {
int numFloors = 5; // Number of floors in the building
Elevator elevator(numFloors);
int numRequests;
std::cout << "Enter the number of floor requests: ";
std::cin >> numRequests;
for (int i = 0; i < numRequests; ++i) {
int floor;
std::cout << "Enter floor request " << i + 1 << ": ";
std::cin >> floor;
elevator.request(floor);
}
std::cout << "Starting elevator operation...\n";
elevator.operate();
return 0;
}