Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <deque>
- #include <string>
- #include <iostream>
- using namespace std;
- struct Ticket {
- int id;
- string name;
- };
- class TicketOffice {
- public:
- void PushTicket(const string& name) {
- last_id_++;
- tickets_.push_back({last_id_, name});
- }
- int GetAvailable() const {
- return tickets_.size();
- }
- int GetAvailable(const string& name) const {
- return count_if(begin(tickets_), end(tickets_), [name](const Ticket& T){return name==T.name;});
- }
- void Invalidate(int minimum) {
- while (!tickets_.empty() && tickets_.front().id <= minimum){
- tickets_.pop_front();
- }
- }
- private:
- int last_id_ = 0;
- deque<Ticket> tickets_;
- };
- int main(){
- TicketOffice tickets;
- tickets.PushTicket("Swan Lake");
- tickets.PushTicket("Swan Lake");
- tickets.PushTicket("Boris Godunov");
- tickets.PushTicket("Boris Godunov");
- tickets.PushTicket("Swan Lake");
- tickets.PushTicket("Boris Godunov");
- tickets.PushTicket("Boris Godunov");
- cout << tickets.GetAvailable() << endl;
- cout << tickets.GetAvailable("Swan Lake") << endl;
- cout << tickets.GetAvailable("Boris Godunov") << endl;
- tickets.Invalidate(3);
- cout << tickets.GetAvailable() << endl;
- cout << tickets.GetAvailable("Swan Lake") << endl;
- cout << tickets.GetAvailable("Boris Godunov") << endl;
- tickets.PushTicket("Swan Lake");
- tickets.PushTicket("Swan Lake");
- cout << tickets.GetAvailable("Swan Lake") << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment