-
10866) 덱 c++백준코딩일기 2020. 11. 4. 20:04
문제 ) www.acmicpc.net/problem/10866
풀이 )
코드 )
#include <iostream> #include <deque> using namespace std; int N; string cmd; deque<int> dq; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N ; while( N-- ) { cin >> cmd; int num = 0; if(cmd == "push_front"){ cin >> num; dq.push_front(num); } else if(cmd == "push_back") { cin >> num; dq.push_back(num); } else if(cmd == "pop_front") { if( !dq.empty() ) { cout << dq.front() << "\n"; dq.pop_front(); } else cout << "-1\n"; } else if(cmd == "pop_back") { if( !dq.empty() ) { cout << dq.back() << "\n"; dq.pop_back(); } else cout << "-1\n"; } else if(cmd == "size") cout << dq.size() << "\n"; else if(cmd == "empty") { if ( !dq.empty() ) cout << "0\n"; else cout << "1\n"; } else if(cmd == "front"){ if( !dq.empty() ) cout << dq.front() << "\n"; else cout << "-1\n"; } else if(cmd == "back"){ if( !dq.empty() ) cout << dq.back() << "\n"; else cout << "-1\n"; } } }
'백준코딩일기' 카테고리의 다른 글
5430) AC c++ (0) 2020.11.05 1021) 회전하는 큐 c++ (0) 2020.11.04 2164) 카드2 c++ (0) 2020.11.04 18258) 큐2 c++ (0) 2020.11.04 10845) 큐 c++ (0) 2020.11.04