ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 14612번 C++ 풀이
    백준 2019. 11. 21. 23:19

    #include <iostream>
    #include <vector>
    #include <math.h>
    #include <queue>
    #include <map>
    #include <stack>
    #include <climits>
    #include <functional>
    #include <string>
    #include <cstring>
    #include <iomanip>
    #include <algorithm>
    #include <queue>

    using namespace std;

    struct PostIt {
    int tableNumber;
    int orderTime;

    PostIt(int tableNumber, int orderTime) {
    this->tableNumber = tableNumber;
    this->orderTime = orderTime;
    }


    };
    inline bool compare(const PostIt& lhs, const PostIt& rhs) {
    if (lhs.orderTime == rhs.orderTime) {
    return lhs.tableNumber < rhs.tableNumber;
    }
    return lhs.orderTime < rhs.orderTime;
    }
    class OrderManager {

    public:
    void qsort(){
    sort(this->orderList.begin(), this->orderList.end(), compare);

    this->print();
    }

    void order(int tableNumber, int orderTime) {
    PostIt p = PostIt(tableNumber, orderTime);

    this->orderList.push_back(p);

    this->print();
    }

    void complete(int tableNumber) {

    for(auto it = this->orderList.begin(); it != this->orderList.end(); ) {

    if (it->tableNumber == tableNumber) {
    it = this->orderList.erase(it);
    }else {
    it++;
    }
    }

    this->print();
    }

    private:

    vector<PostIt> orderList;

    void print() {
    if (this->orderList.empty()) {
    cout << "sleep\n";
    return;
    }
    for (auto postIt: this->orderList) {
    cout << postIt.tableNumber << ' ';
    }
    cout << '\n';
    }


    };


    int main(){

    ios_base::sync_with_stdio(false);
    priority_queue<int, vector<int>, greater<>> pq;
    OrderManager *orderManager = new OrderManager();

    int n, m;
    cin >> n >> m;

    for (auto i=0; i<n; i++) {
    string command;
    cin >> command;

    if (command == "order") {
    int tableNumeber, orderTime;
    cin >> tableNumeber >> orderTime;
    orderManager->order(tableNumeber, orderTime);
    } else if (command == "sort") {
    orderManager->qsort();
    } else if (command == "complete") {
    int tableNumber;
    cin >> tableNumber;
    orderManager->complete(tableNumber);
    }
    }

    return 0;
    }

    '백준' 카테고리의 다른 글

    PS(알고리즘) 오픈 톡방 신입부원 대 모집!!  (0) 2019.12.01
    백준 14619번 c++ 풀이  (0) 2019.11.24
    백준 13413번 C++ 풀이  (0) 2019.11.09
    백준 2096번 C++ 풀이  (0) 2019.10.29
    백준 17070번 C++ 풀이  (0) 2019.08.30
Designed by Tistory.