BOJ 10828:スタック実装
1762 ワード
[問題のショートカット](10828:スタック)
//STL 사용
#include<iostream>
#include<string>
#include<stack>
using namespace std;
const int MAX_st_SIZE = 1000;
//10828
int main() {
int num = 0;
string str;
cin >> num;
stack<int> st;
int x;
for (int i = 0; i < num; i++) {
cin >> str;
if (str == "push") {
cin >> x;
st.push(x);
}
else if (str == "pop") {
if (!st.empty()) {
cout << st.top() << endl;
st.pop();
}
else
cout << -1 << endl;
}
else if (str == "size")
cout << st.size() << endl;
else if (str == "empty") {
if (st.empty())
cout << 1 << endl;
else
cout << 0 << endl;
}
else if (str == "top")
if (st.empty())
cout << -1 << endl;
else
cout << st.top() << endl;
}
return 0;
}
Reference
この問題について(BOJ 10828:スタック実装), 我々は、より多くの情報をここで見つけました https://velog.io/@mam07065/BOJ-10828-스택-구현テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol