PRoblem Description refresh最近發了一筆橫財,開了一家停車場。由于土地有限,停車場內停車數量有限,但是要求進停車場的車輛過多。當停車場滿時,要進入的車輛會進入便道等待,最先進入便道的車輛會優先 進入停車場,而且停車場的結構要求只出去的車輛必須是停車場中最后進去的車輛?,F告訴你停車場容量N以及命令數M,以及一些命令(Add num 表示車牌號為num的車輛要進入停車場或便道, Del 表示停車場中出去了一輛車,Out 表示便道最前面的車輛不再等待,放棄進入停車場)。假設便道內的車輛不超過1000000. Input 輸入為多組數據,每組數據首先輸入N和M(0<?。?,m?。?00000),接下來輸入M條命令。 Output 輸入結束后,如果出現停車場內無車輛而出現Del或者便道內無車輛而出現Out,則輸出Error,否則輸出停車場內的車輛,最后進入的最先輸出,無車輛不輸出。 Example Input
2 6Add 18353364208Add 18353365550Add 18353365558Add 18353365559DelOutExample Output
1835336555818353364208Hint
Author
#include <iostream>#include <algorithm>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <bits/stdc++.h>#include <stack>#include <deque>#include <queue>using namespace std;typedefstruct node{ char p[20];}ras;int main(){ stack< ras> p; queue <ras> g; int n, m; while(~scanf("%d%d", &n, &m)) { while(!p.empty()) { p.pop(); } while(!g.empty()) { g.pop(); } int top=1; while(m--) { char kk[5]; scanf("%s", kk); if(strcmp(kk, "Add")==0) { struct node l; scanf("%s", l.p); if(p.size()<n) { p.push(l); } else g.push(l); } else if(strcmp(kk, "Del")==0) { if(p.empty()) { top=0; } else { p.pop(); if(!g.empty()) { p.push(g.front()); g.pop(); } } } else if(strcmp(kk, "Out")==0) { if(g.empty()) { top=0; } else g.pop(); } } if(top) while(!p.empty()) { printf("%s/n", p.top().p); p.pop(); } else printf("Error/n"); } return 0;}新聞熱點
疑難解答