排队做操迟到 c++
时间: 2023-11-24 22:51:48 浏览: 55
以下是C++实现排队做操迟到的代码:
```cpp
#include<iostream>
#include<queue>
using namespace std;
int main(){
queue<string> q;
int n;
cin >> n;
for(int i = 0; i < n; i++){
string name;
cin >> name;
q.push(name);
}
int m;
cin >> m;
for(int i = 0; i < m; i++){
string name;
cin >> name;
while(!q.empty()){
string front_name = q.front(); q.pop();
if(front_name != name){
q.push(front_name);
}else{
break;
}
}
}
while(!q.empty()){
cout << q.front() << endl;
q.pop();
}
return 0;
}
```
相关问题
窗口排队管理系统c++
下面是一个简单的窗口排队管理系统的 C++ 代码示例:
```c++
#include <iostream>
#include <queue>
using namespace std;
struct Customer {
int id;
int service_time;
};
int main() {
queue<Customer> customers;
int num_customers;
int total_service_time = 0;
cout << "请输入顾客数量:" << endl;
cin >> num_customers;
for (int i = 1; i <= num_customers; i++) {
Customer customer;
customer.id = i;
cout << "请输入顾客 " << i << " 的服务时间:" << endl;
cin >> customer.service_time;
customers.push(customer);
}
cout << "当前窗口空闲" << endl;
while (!customers.empty()) {
Customer customer = customers.front();
customers.pop();
total_service_time += customer.service_time;
cout << "顾客 " << customer.id << " 开始服务,服务时间为 " << customer.service_time << ",累计服务时间为 " << total_service_time << endl;
}
cout << "所有顾客服务结束,总服务时间为 " << total_service_time << endl;
return 0;
}
```
在这个示例中,顾客被定义为一个结构体,包含顾客的编号和需要的服务时间。使用 `queue` 存储所有顾客,然后依次处理每个顾客,计算累计服务时间。最终输出总服务时间。
这只是一个简单的示例,实际的窗口排队管理系统可能需要更复杂的逻辑和功能。
银行窗口排队管理系统C++
好的,下面是一个简单的银行窗口排队管理系统的 C++ 代码示例:
```c++
#include <iostream>
#include <queue>
#include <string>
using namespace std;
class Customer {
public:
string name;
int age;
string id;
string phone;
};
class QueueManager {
private:
queue<Customer> q;
public:
void addCustomer(Customer customer) {
q.push(customer);
}
void serveNextCustomer() {
if (!q.empty()) {
Customer c = q.front();
q.pop();
cout << "服务客户:" << c.name << endl;
} else {
cout << "暂无客户排队" << endl;
}
}
};
int main() {
QueueManager qm;
Customer c1 = {"Tom", 25, "123456", "13888888888"};
Customer c2 = {"Lucy", 30, "654321", "13999999999"};
qm.addCustomer(c1);
qm.addCustomer(c2);
qm.serveNextCustomer(); // 服务客户:Tom
qm.serveNextCustomer(); // 服务客户:Lucy
qm.serveNextCustomer(); // 暂无客户排队
return 0;
}
```
上述代码实现了一个简单的银行窗口排队管理系统,包含 Customer 类和 QueueManager 类。其中 Customer 类表示客户信息,QueueManager 类表示排队管理系统,包含添加客户、服务下一个客户和暂无客户排队三个方法。您可以根据需要进行修改和扩展。