📄 c3_car.cpp
字号:
/*
停车场模拟程序
BY:wangyucao
*/
#include<iostream>
#include<fstream>
#include<stack>
#include<queue>
using namespace std;
struct Car{
int num; //车辆编号
int time; //进入停车场的时间
};
int main()
{
stack<Car> car; //停车场
stack<Car> car_out; //车辆出栈时的存储栈
queue<Car> outside; //便道
Car now;
ifstream fin("car.in");
ofstream fout("car.out");
char sit;
int i,j,k,n,price,number,time;
fin>>n>>price; //输入停车场容量和单位时间停车单价
while(fin>>sit>>now.num>>now.time && sit!='E') //输入当前车辆的状态,汽车编号和时间
{
switch(sit){
case 'A': //如果是来停车场的车辆,停车场有空位时输出车辆在停车场中的位置
if(car.size()<n) {car.push(now); fout<<"A "<<"停车场 "<<car.size()<<endl;}
//如果停车场没有空位,则停在便道中,输出便道中的位置。
else {outside.push(now); fout<<"A 便道 "<<outside.size()<<endl;}
break;
case 'D':
Car temp;
temp=car.top();
while(temp.num!= now.num)
{
car.pop();
car_out.push(temp);
temp=car.top();
}
car.pop();
//如果车辆离开,则输出离开的车辆编号和离开时间及收费情况
fout<<"D "<<temp.num<<' '<<now.time-temp.time<<' '<<(now.time-temp.time)*price<<endl;
while(!car_out.empty())
{
temp=car_out.top();
car_out.pop();
car.push(temp);
}
if(!outside.empty())
{
temp=outside.front();
temp.time=now.time;
outside.pop();
car.push(temp);
}
break;
case 'E':
break;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -