Notice
Recent Posts
Recent Comments
Link
Programmer
10828번 스택 본문
#include <iostream>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
void solve() {
stack<int> stk;
string command;
int inputData;
int commandLine;
cin >> commandLine;
for (int i = 0; i < commandLine; i++) {
cin >> command;
if (!command.compare("push")) {
cin >> inputData;
stk.push(inputData);
}
else if (!command.compare("pop")) {
if (stk.size() == 0)
cout << "-1" << endl;
else {
cout << stk.top() << endl;
stk.pop();
}
}
else if (!command.compare("size")) {
cout << stk.size() << endl;
}
else if (!command.compare("empty")) {
cout << stk.empty() << endl;
}
else if (!command.compare("top")) {
if (stk.size() == 0)
cout << "-1" << endl;
else
cout << stk.top() << endl;
}
}
}
int main() {
solve();
return 0;
}
'백준' 카테고리의 다른 글
1158 요세푸스 문제 (0) | 2020.04.13 |
---|---|
1181번 단어 정렬 (0) | 2020.04.11 |
3986번 좋은 단어 (0) | 2020.04.04 |
10845번 큐 (0) | 2020.04.02 |
Comments