问题遇到的现象和发生背景
CLZ 银行只有两个接待窗口,VIP 窗口和普通窗口,VIP 用户进入VIP 窗口排队,剩下的进入普通窗口排队.
现有M 次操作,操作有四种类型,如下:
IN name V:表示一名叫 name 的用户到 VIP 窗口排队
OUT V:表示 VIP 窗口队头的用户离开排队
IN name N:表示一名叫 name 的用户到普通窗口排队
OUT N:表示普通窗口队头的用户离开排队
求 M 次操作结束后 VIP 窗口队列和普通窗口队列中的姓名。
输入描述:第一行是一个整数 M 格式如下:
IN name V
OUT V
IN name N
OUT N
输出描述:
输出 M 次操作后 VIP 窗口队列和普通窗口队列中的姓名(从头到尾),先输出 VIP 窗口队列后输出普通窗口队列。
问题相关代码,请勿粘贴截图
#include<iostream>
#include<malloc.h>
using namespace std;
typedef struct queue
{string data[100];
int front,rear;
}Queue;
void InitQueue(Queue *&q)
{q=(Queue *)malloc(sizeof(Queue));
q->front=q->rear=0;
}
bool enQueue(Queue *&q,string name)
{
q->data[q->rear]=name;
q->rear++;
return true;
}
bool deQueue(Queue *&q)
{
if(q->front==q->rear)
return false;
q->front++;
return true;
}
string get(Queue *q,string &e)
{
e=q->data[q->front];
return e;
}
int main()
{int m;
string e,h;
cin>>m;
Queue *VQ;
Queue *NQ;
InitQueue(VQ);
InitQueue(NQ);
while(m--)
{
string one,name,type;
cin>>one;
if(one=="IN")
{
cin>>name>>type;
if(type=="V")
enQueue(VQ,name);
else
enQueue(NQ,name);
}
else
{cin>>type;
if(type=="V")
deQueue(VQ);
else
deQueue(NQ);
}}
get(VQ,e);
get(NQ,h);
while(deQueue(VQ))
{get(VQ,e);
cout<<e<<" ";
}
while(deQueue(NQ))
{get(NQ,h);
cout<<h<<" ";
}
cout<<endl;
return 0;
}
运行结果及报错内容
没有输出结果
我的解答思路和尝试过的方法
我想要达到的结果
操作完成后输出队列中的值