日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

B - Ada and Queue

發布時間:2024/8/23 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 B - Ada and Queue 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Ada the Ladybug has many things to do. She puts them into her queue. Anyway she is very indecisive, so sometime she uses the top, sometime the back and sometime she decides to reverses it.

Input

The first line consists of?1 ≤ Q ≤ 106, number of queries. Each of them contains one of following commands

back - Print number from back and then erase it

front - Print number from front and then erase it

reverse - Reverses all elements in queue

push_back?N?- Add element?N?to back

toFront?N?- Put element?N?to front

All numbers will be?0 ≤ N ≤ 100

Output

For each back/front query print appropriate number.

If you would get this type of query and the queue would be empty, print "No job for Ada?" instead.

Example Input

15 toFront 93 front back reverse back reverse toFront 80 push_back 53 push_back 50 front front reverse push_back 66 reverse front

Example Output

93 No job for Ada? No job for Ada? 80 53

66

解析:雙向隊列模擬;主要是reverse,定義一個flag標記,對頭隊尾即可;

#include<bits/stdc++.h> using namespace std; int Q;char s[15]; int num; deque<int>q; deque<int>qq;deque<int>::iterator it;int main() {int ans=0;scanf("%d",&Q);for(int i=0;i<Q;i++){scanf("%s",s);if(s[0]=='t'){scanf("%d",&num);if(ans%2==0)q.push_front(num);elseq.push_back(num);}else if(s[0]=='p'){scanf("%d",&num);if(ans%2==0)q.push_back(num);elseq.push_front(num);}else if(s[0]=='f'){if(q.empty()){puts("No job for Ada?");}else{if(ans%2==0){int top=q.front();q.pop_front();printf("%d\n",top);}else{int tail=q.back();q.pop_back();printf("%d\n",tail);}}}else if(s[0]=='b'){if(q.empty()){puts("No job for Ada?");}else{if(ans%2==0){int tail=q.back();q.pop_back();printf("%d\n",tail);}else{int top=q.front();q.pop_front();printf("%d\n",top);}}}else{ans++;}} }

總結

以上是生活随笔為你收集整理的B - Ada and Queue的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。