Refresh in the parking lot Time limit:1000ms Memory limit:65536k Topic Description Refresh has recently made a windfall and opened a parking lot. Due to limited land, parking in the car park is limited, but the number of vehicles required to enter the parking lot. When the parking lot is full, the vehicles to be entered will be on the sidewalk, and the first vehicles entering the sidewalk will be given priority access to the parking lot, and the structure of the parking lot must be the last vehicle in the parking lot. Now tell you the parking capacity N and the number of commands M, as well as some commands (Add num indicates that a vehicle with a license plate number num is going to a parking lot or sidewalk, Del means a car in the parking lot, out of the front of the sidewalk, the vehicle is no longer waiting, giving up access to the parking lot). Assume that there are no more than 1000000 vehicles in the sidewalk. Input input for multiple sets of data, each group of data first enter N and m (0< n,m <200000), followed by the M command. After the output input is finished, if there is no vehicle in the parking lot and there is no vehicle in the sidewalk to appear out, then output error, otherwise the output car park in the vehicle, the last entry of the first output, no vehicle output. Sample input
2 6Add 18353364208Add 18353365550Add 18353365558Add 18353365559DelOut
Sample output
1835336555818353364208
1#include <stdio.h>2#include <string.h>3 4 Charstr[4], num[ -];5 Chars[300010][ +], q[100010][ +];6 intN, M, Top1, TOP2, FO;7 8 intMain ()9 {Ten while(~SCANF ("%d%d",&n,&m)) One { A intflag=1; -top1=0;//The subscript of the parking lot -Top2=0;//Subscript of the sidewalk thefo=0;//traversing the subscript of the sidewalk starting from 0 - - for(intI=1; i<=m; i++) - { +scanf"%s", str); - if(strcmp (str,"ADD")==0) + { Ascanf"%s", num); at if(top1<n)//If the parking lot does not reach the maximum amount of parking -strcpy (s[top1++], num); - Else //The parking lot reaches the maximum capacity, and the remaining vehicles enter the sidewalk. -strcpy (q[top2++], num); - } - Else if(strcmp (str,"Del")==0) in { - if(top1!=0) to { +top1--; - if(Fo <top2) thestrcpy (s[top1++], q[fo++]); * } $ ElsePanax Notoginsengflag=0; - } the Else if(strcmp (str," out")==0) + { A if(fo<top2) thefo++; + Else -flag=0; $ } $ } - if(flag) - { the for(intI=top1-1; i>=0; i--) -printf"%s\n", S[i]);Wuyi } the Else -printf"error\n"); Wu } - return 0; About}
1#include <stdio.h>2#include <string.h>3 4 Charstr[4], num[ -];5 Chars[300010][ +], q[100010][ +];6 intN, M, Top1, TOP2, FO;7 8 intMain ()9 {Ten while(~SCANF ("%d%d",&n,&m)) One { A intflag=1; -top1=0;//The subscript of the parking lot -Top2=0;//Subscript of the sidewalk thefo=0;//traversing the subscript of the sidewalk starting from 0 - - for(intI=1; i<=m; i++) - { +scanf"%s", str); - if(strcmp (str,"ADD")==0) + { Ascanf"%s", num); at if(top1<n)//If the parking lot does not reach the maximum amount of parking -strcpy (s[top1++], num); - Else //The parking lot reaches the maximum capacity, and the remaining vehicles enter the sidewalk. -strcpy (q[top2++], num); - } - Else if(strcmp (str,"Del")==0) in { - if(top1!=0) to { +top1--; - if(Fo <top2) thestrcpy (s[top1++], q[fo++]); * } $ ElsePanax Notoginsengflag=0; - } the Else if(strcmp (str," out")==0) + { A if(fo<top2) thefo++; + Else -flag=0; $ } $ } - if(flag) - { the for(intI=top1-1; i>=0; i--) -printf"%s\n", S[i]);Wuyi } the Else -printf"error\n"); Wu } - return 0; About}
Refresh Parking (analog)