Refresh parking lot (stack and queue STL)

Source: Internet
Author: User

Refresh parking lot (stack and queue STL)

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
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         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
        
          P; // remember to create stacks and queues in the loop. Wass are crying three times. Queue
         
           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" <
          
           

Zookeeper

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.