SDUT,山東理工大學

來源:互聯網
上載者:User

SDUT,山東理工大學

題目描述 refresh最近發了一筆橫財,開了一家停車場。由於土地有限,停車場內停車數量有限,但是要求進停車場的車輛過多。當停車場滿時,要進入的車輛會進入便道等待,最先進入便道的車輛會優先進入停車場,而且停車場的結構要求只出去的車輛必須是停車場中最後進去的車輛。現告訴你停車場容量N以及命令數M,以及一些命令(Add num 表示車牌號為num的車輛要進入停車場或便道,Del 表示停車場中出去了一輛車,Out 表示便道最前面的車輛不再等待,放棄進入停車場)。假設便道內的車輛不超過1000000.輸入 首先輸入N和M(0< n,m <200000),接下來輸入M條命令。輸出 輸入結束後,如果出現停車場內無車輛而出現Del或者便道內無車輛而出現Out,則輸出Error,否則輸出停車場內的車輛,最後進入的最先輸出,無車輛不輸出。樣本輸入

2 6Add 18353364208Add 18353365550Add 18353365558Add 18353365559DelOut
樣本輸出
1835336555818353364208
用一個棧和一個對列類比一下就好了。。資料好弱
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <deque>#include <stack>#include <map>#include <set>#define ll long long#define maxn 1010#define pp pair<int,int>#define INF 0x3f3f3f3f#define max(x,y) ( ((x) > (y)) ? (x) : (y) )#define min(x,y) ( ((x) > (y)) ? (y) : (x) )using namespace std;int n,m,top,st,en;char s[300010][33],q[300010][33];int main(){while(~scanf("%d%d",&n,&m)){int ok=1;top=0;st=0;en=0;char op[4],x[33];for(int i=1;i<=m;i++){scanf("%s",op);if(!strcmp(op,"Add")){scanf("%s",x);if(top<n)strcpy(s[top++],x);elsestrcpy(q[en++],x);}else if(!strcmp(op,"Del")){if(top){top--;if(st<en)strcpy(s[top++],q[st++]);}elseok=0;}else if(!strcmp(op,"Out")){if(st<en)st++;elseok=0;}}if(ok){for(int i=top-1;i>=0;i--)printf("%s\n",s[i]);}elseputs("Error");}return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.