标签:
2 7 0 1 [Sword_Art_Online] 1 [Your_Lie_in_April] 2 [sakura_sou_no_pet_na_kanojo] 0 0 0 6 1 [Your_Lie_in_April] 1 [Your_Lie_in_April] 2 [Is_the_order_a_rabbit] 3 [Is_the_order_a_rabbit] 0 0
-1 sakura_sou_no_pet_na_kanojo Sword_Art_Online Your_Lie_in_April Your_Lie_in_April -1
虽然没学过c++ 。。
感觉应该和java差不多。。。
题意中因为要从队尾 队首加入 所以选用---------------------双端队列
为了判断是否看过某番 ,为了番名的唯一性----------------set容器
剩下的就是模拟了
#include <iostream> #include <string.h> #include <stdio.h> #include <queue> #include <set> using namespace std; int main() { set<string>s; deque<string>q; int ncase,n; scanf("%d",&ncase); while(ncase--) { s.clear(); while(!q.empty()) q.pop_back(); cin>>n; for(int i=0;i<n;i++) { int x; cin>>x; if(x==0) { if(!q.empty()) { string x1=q.front();q.pop_front(); if(s.find(x1)==s.end()) { cout<<x1<<endl; s.insert(x1); } else { cout<<-1<<endl; } } else { cout<<-1<<endl; } } if(x==1) { string x2; cin>>x2; q.push_back(x2.substr(1,x2.length()-2)); } if(x==2) { string x2; cin>>x2; q.push_front(x2.substr(1,x2.length()-2)); } if(x==3) { string x2; cin>>x2; x2=x2.substr(1,x2.length()-2); int count=q.size(); while(count--) { string x3=q.front();q.pop_front(); if(x3.compare(x2)!=0) { q.push_back(x3); } } } } } return 0; }
补番计划 (长沙理工大学第十一届程序设计竞赛)(双端队列+set容器+string)
标签:
原文地址:http://blog.csdn.net/su20145104009/article/details/51170818