Parking lot for Refresh Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ Refresh recently made a fortune and opened a parking lot. Due to limited land, the number of parking in the parking lot is limited, but there are too many vehicles required to enter the parking lot. When the parking lot is full, the vehicles to enter will enter the convenient road and wait. The first vehicles to enter the convenient road will first enter the parking lot, in addition, the structure of the parking lot requires that only the vehicles going out must be the last vehicles in the parking lot. Now we will tell you the parking lot capacity n and the command m, and some commands (add num indicates that a vehicle with the license plate number num is going to enter the parking lot or driveway. Del indicates that a car is going out in the parking lot, out indicates that the vehicle at the top of the sidewalk is no longer waiting and stops entering the parking lot ). Assume that the number of vehicles in the driveway cannot exceed 1000000. Input N and M (0 <n, m <200000), and then input m commands. After the output input is complete, if there is no vehicle in the parking lot and del occurs or there is no vehicle in the driveway and out occurs, an error is output. Otherwise, the vehicles in the parking lot are output first, no vehicle, no output. Sample Input
2 6Add 18353364208Add 18353365550Add 18353365558Add 18353365559DelOut
Sample output
1835336555818353364208
Prompt source sample program
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <algorithm> # include <iostream> # include <queue> # include <stack> # include <string> using namespace STD; int main () {char STR [20]; string s; int flag = 0; // used to mark whether the stack and queue are empty. If it is null, del or out operations are continued, error; int n, m, I; while (~ Scanf ("% d", & N, & M) {stack <string> P; // remember to create a stack and queue in the loop, wa3 times, crying. Queue <string> q; flag = 0; for (I = 1; I <= m; I ++) {CIN> STR; If (strcmp (STR, "add") = 0) {CIN> S; If (P. size () = N) // It indicates that the parking lot is full. push (s); // the vehicle enters the convenient route else p. push (s);} else if (strcmp (STR, "Del") = 0) {If (P. empty () Flag = 1; else {P. pop (); If (! Q. empty () {P. push (Q. front (); q. pop () ;}} else if (strcmp (STR, "out") = 0) {If (Q. empty () Flag = 1; else Q. pop () ;}}if (FLAG) cout <"error" <Endl; else {While (! P. Empty () {cout <p. Top () <Endl; p. Pop () ;}} return 0 ;}
Zookeeper
Refresh parking lot (stack and queue STL)