#include <iostream>
#include <stack>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
stack<int>st;
int N; cin >> N;
while (N--) {
string cmd; cin >> cmd;
if (cmd == "push") {
int num; cin >> num;
st.push(num);
}
else if (cmd == "top") {
if (st.empty()) cout << -1<<"\n";
else cout << st.top()<<"\n";
}
else if (cmd == "size") cout << st.size()<<"\n";
else if (cmd == "pop") {
if (st.empty()) cout << -1 << "\n";
else {
cout << st.top()<<"\n";
st.pop();
}
}
else if (cmd == "empty") {
if (st.empty()) cout << 1 << "\n";
else cout << 0 << "\n";
}
}
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 10867๋ฒ - ์ค๋ณต ๋นผ๊ณ ์ ๋ ฌํ๊ธฐ (0) | 2021.10.25 |
---|---|
[๋ฐฑ์ค,c++] 10866๋ฒ - ๋ฑ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10845๋ฒ - ํ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10825๋ฒ - ๊ตญ์์ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10824๋ฒ - ๋ค ์ (0) | 2021.10.25 |
[๋ฐฑ์ค,c++] 10823๋ฒ - ๋ํ๊ธฐ2 (0) | 2021.10.24 |
๋๊ธ