rendered paste body//main question
//what happens next?
//-Departure
//-Arrival
//in.txt
//main.exe
//main.exe < in.txt puts the contents of in.txt into CIN
#include <iostream>
#include <queue>
using namespace std;
struct Customer
{
int arrival_time;
int items;
Customer(int a, int i)
{
arrival_time = a;
items = i;
}
};
class Checkout
{
public:
void depart();
void arrive(Customer c);
bool empty() const;
int next_departure_time() const;
private:
queue<Customer> q_;
int departure_time_;
};
void Checkout::arrive(Customer c)
{
q_.push(c);
if(empty())
{
departure_time_ = c.arrival_time + c.items;
//print out arrival event
}
}
void Checkout::depart()
{
//assert queue isn't empty assert(!empty())
Customer c = q_.front();
q_.pop();
if(!q_.empty())
departure_time_ += q_.front().items;
//departure event
}
bool Checkout::empty() const
{
return q_.empty();
}
int Checkout::next_departure_time() const
{
//assert(!empty());
return departure_time_;
}
int main()
{
while(cin >> arrival >> items)
Customer c;
c.arrival_time = arrival;
c.items = items;
while(!empty() && next_departure <= arrival) //only makes sense as long as queue isn't empty
checkout.depart();
while(!empty())
{
checkout.arrive(c(arrival, items));
}
while(!q.empty())
depart();
}