PRoblem Description refresh最近發(fā)了一筆橫財(cái),開(kāi)了一家停車(chē)場(chǎng)。由于土地有限,停車(chē)場(chǎng)內(nèi)停車(chē)數(shù)量有限,但是要求進(jìn)停車(chē)場(chǎng)的車(chē)輛過(guò)多。當(dāng)停車(chē)場(chǎng)滿(mǎn)時(shí),要進(jìn)入的車(chē)輛會(huì)進(jìn)入便道等待,最先進(jìn)入便道的車(chē)輛會(huì)優(yōu)先 進(jìn)入停車(chē)場(chǎng),而且停車(chē)場(chǎng)的結(jié)構(gòu)要求只出去的車(chē)輛必須是停車(chē)場(chǎng)中最后進(jìn)去的車(chē)輛?,F(xiàn)告訴你停車(chē)場(chǎng)容量N以及命令數(shù)M,以及一些命令(Add num 表示車(chē)牌號(hào)為num的車(chē)輛要進(jìn)入停車(chē)場(chǎng)或便道, Del 表示停車(chē)場(chǎng)中出去了一輛車(chē),Out 表示便道最前面的車(chē)輛不再等待,放棄進(jìn)入停車(chē)場(chǎng))。假設(shè)便道內(nèi)的車(chē)輛不超過(guò)1000000. Input 輸入為多組數(shù)據(jù),每組數(shù)據(jù)首先輸入N和M(0< n,m?。?00000),接下來(lái)輸入M條命令。 Output 輸入結(jié)束后,如果出現(xiàn)停車(chē)場(chǎng)內(nèi)無(wú)車(chē)輛而出現(xiàn)Del或者便道內(nèi)無(wú)車(chē)輛而出現(xiàn)Out,則輸出Error,否則輸出停車(chē)場(chǎng)內(nèi)的車(chē)輛,最后進(jìn)入的最先輸出,無(wú)車(chē)輛不輸出。 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;}新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注