列表

详情


CPP48. 智能排队系统

描述

请设计一个排队程序,用户有普通客人和 VIP 客人之分,VIP 客人不排队(即 VIP 客人在队列头部),请将已有的guest1和guest2放入队列中(guest1排在guest2前),并将VIP客人新增至队列头部。

输入描述

输出描述

VIP客人姓名 guest1姓名 guest2姓名(每个客人的名字用空格隔开)

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 2ms, 内存消耗: 272KB, 提交时间: 2021-11-07

#include <iostream>
#include <deque>
using namespace std;

class Guest {
public:
    string name;
    bool vip;

    Guest(string name, bool vip) {
        this->name = name;
        this->vip = vip;
    }
};

int main() {

    Guest guest1("张三", false);
    Guest guest2("李四", false);
    Guest vipGuest("王五", true);
    deque<Guest> deque;
    // write your code here......
    deque.push_back(guest1);
    deque.push_back(guest2);
    deque.push_front(vipGuest);
    

    for (Guest g : deque) {
        cout << g.name << " ";
    }

    return 0;
}

C++ 解法, 执行用时: 2ms, 内存消耗: 276KB, 提交时间: 2021-11-06

#include <iostream>
#include <deque>
using namespace std;

class Guest {
public:
    string name;
    bool vip;

    Guest(string name, bool vip) {
        this->name = name;
        this->vip = vip;
    }
};

int main() {

    Guest guest1("张三", false);
    Guest guest2("李四", false);
    Guest vipGuest("王五", true);
    deque<Guest> deque;

    // write your code here......
    deque.emplace_back(guest1);
    deque.emplace_back(guest2);
    deque.emplace_front(vipGuest);

    for (Guest g : deque) {
        cout << g.name << " ";
    }

    return 0;
}

C++ 解法, 执行用时: 2ms, 内存消耗: 280KB, 提交时间: 2022-05-17

#include <iostream>
#include <deque>
using namespace std;

class Guest {
public:
    string name;
    bool vip;

    Guest(string name, bool vip) {
        this->name = name;
        this->vip = vip;
    }
};

int main() {

    Guest guest1("张三", false);
    Guest guest2("李四", false);
    Guest vipGuest("王五", true);
    deque<Guest> deque;//定义deque容器

    // write your code here......
    deque.push_back(guest1);
    deque.push_back(guest2);
    deque.push_front(vipGuest);
    

    for (Guest g : deque) {
        cout << g.name << " ";
    }

    return 0;
}

C++ 解法, 执行用时: 2ms, 内存消耗: 280KB, 提交时间: 2022-04-16

#include <iostream>
#include <deque>
using namespace std;

class Guest {
public:
    string name;
    bool vip;

    Guest(string name, bool vip) {
        this->name = name;
        this->vip = vip;
    }
};

int main() {

    Guest guest1("张三", false);
    Guest guest2("李四", false);
    Guest vipGuest("王五", true);
    deque<Guest> deque;
    deque.push_back(guest1);
    deque.push_back(guest2);
    deque.push_front(vipGuest);


    

    for (Guest g : deque) {
        cout << g.name << " ";
    }

    return 0;
}

C++ 解法, 执行用时: 2ms, 内存消耗: 280KB, 提交时间: 2021-11-17

#include <iostream>
#include <deque>
using namespace std;

class Guest {
public:
    string name;
    bool vip;

    Guest(string name, bool vip) {
        this->name = name;
        this->vip = vip;
    }
};

int main() {

    Guest guest1("张三", false);
    Guest guest2("李四", false);
    Guest vipGuest("王五", true);
    deque<Guest> deque;

    // write your code here......
    deque.push_front(vipGuest);
    deque.push_back(guest1);
    deque.push_back(guest2);
    for (Guest g : deque) {
        cout << g.name << " ";
    }

    return 0;
}

上一题