Skip to content

Commit

Permalink
BaekJoon
Browse files Browse the repository at this point in the history
  • Loading branch information
witheunjin committed Mar 3, 2020
1 parent 4e0cb7c commit c0a1627
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions BaekJoon/10828_스택.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

stack<int> s;
void match(string para) {
if (para == "push") {
int x;
cin >> x;
s.push(x);
}
else if (para == "pop") {
if (s.empty()) cout << -1 << endl;
else { cout << s.top() << endl; s.pop(); }
}
else if (para == "size") {
cout << s.size() << endl;
}
else if (para == "empty") {
if (s.empty()) cout << 1 << endl;
else cout << 0 << endl;
}
else if (para == "top") {
if (s.empty()) cout << -1 << endl;
else cout << s.top() << endl;
}
}
int main() {
int N;
cin >> N;
string command;
for (int i = 0; i < N; ++i) {
cin >> command;
match(command);
}
return 0;
}

0 comments on commit c0a1627

Please sign in to comment.