Parking lot for sdut OJ 2088 refresh

Source: Internet
Author: User
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

Algorithm Analysis: Uses STL stacks and queues for better description.
The stack is used to simulate the parking lot. Use a queue to simulate the convenience of waiting for a car. First, use the advanced parking lot.
Note: even if the intermediate input processing command is unreasonable and an error needs to be output, you must output the error after all the commands are input. That is to say
Once an unreasonable situation occurs, you need to mark it.
# Include <stdio. h> # include <iostream> # include <string. h >#include <string >#include <algorithm> # include <stack> # include <queue> using namespace STD; int n, m; char s [50]; string T; int main () {int DD, I; int flag; while (scanf ("% d", & N, & M )! = EOF) {stack <string> q; queue <string> W; flag = 1; for (I = 0; I <m; I ++) {CIN> S; if (s [0] = 'A') {CIN> T; If (Q. size () = N) {W. push (t); // enter the queue} else {q. push (t) ;}} else if (s [0] = 'D') {If (Q. empty () {flag = 0;} else {q. pop (); If (! W. empty () {T = W. front (); q. push (t); W. pop () ;}} else {If (W. empty () {flag = 0;} else {W. pop () ;}}if (flag = 0) printf ("error \ n"); else {While (! Q. Empty () {T = Q. Top (); cout <t <Endl; q. Pop () ;}} return 0 ;}

 

Parking lot for sdut OJ 2088 refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.