卬高杯
q
に対してq.push()
、先頭要素取得はq.front()
、先頭要素削除はq.pop()
で行うことができます。また、すべて`O(1)`で行うことができます。だけどいいかな
が出力で共通しているため省略することができます。
#include<bits/stdc++.h>
using namespace std;
int main(){
int Q;
cin>>Q;
queue<string> q;
int q_type;
while(Q--){
cin>>q_type;
if(q_type==1){
string S;
cin>>S;
q.push(S);
}
else if(q_type==2){
// q.empty()でqが空かを判別できる。
if(q.empty()){
cout<<"何もなくてごめんね"<<endl;
continue;
}
cout<<q.front();
if(q.size()==1){
cout<<"しかなかったん";
}
cout<<"だけどいいかな"<<endl;
q.pop();
}
}
// q.size()でqの大きさを取得できる。
cout<<q.size()<<endl;
}
Coffe
とかいう未知の飲み物。興味があります。