-
10828) 스택 c++백준코딩일기 2020. 11. 5. 13:47
문제 ) www.acmicpc.net/problem/10828
풀이 )
코드 )
#include <iostream> #include <stack> using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); stack<int> s; int t; cin >> t; while (t--) { string cmd; cin >> cmd; if (cmd == "push") { int num; cin >> num; s.push(num); } else if (cmd =="top") { if (s.empty()) cout << "-1" << "\n"; else cout << s.top() << "\n"; } else if (cmd == "size") { cout << s.size() << "\n"; } else if (cmd == "pop") { if (s.empty()) cout << "-1" << "\n"; else { cout << s.top() << "\n"; s.pop(); } } else if (cmd == "empty") { if (s.empty()) cout << "1" << "\n"; else cout << "0" << "\n"; } } }
'백준코딩일기' 카테고리의 다른 글
10799) 쇠막대기 c++ (0) 2020.11.17 4949) 균형잡힌 세상 c++ (0) 2020.11.17 1158) 요세푸스 문제 (0) 2020.11.05 5397) 키로거 c++ (0) 2020.11.05 1406) 에디터 c++ (0) 2020.11.05