VioletaBabel
10828번: 스택 본문
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
using namespace std;
int main()
{
stack<int> s;
int n;
char com[6];
cin >> n;
for (int i = 0, a; i < n; ++i)
{
scanf("%s", &com);
if (!strcmp(com, "push"))
{
cin >> a;
s.push(a);
}
else if (!strcmp(com, "pop"))
if (s.empty())
cout << -1 << endl;
else
{
cout << s.top() << endl;
s.pop();
}
else if (!strcmp(com, "size"))
cout << s.size() << endl;
else if (!strcmp(com, "empty"))
cout << s.empty() << endl;
else if (!strcmp(com, "top"))
{
if (s.empty())
cout << -1 << endl;
else
cout << s.top() << endl;;
}
}
}
'백준 > 백준-C++' 카테고리의 다른 글
10866번: 덱 (0) | 2017.05.26 |
---|---|
11004번: K번째 수 (0) | 2017.05.26 |
1406번: 에디터 (0) | 2017.05.26 |
1158번: 조세퍼스 문제 (0) | 2017.05.26 |
3622번: 어떤 호박의 할로윈 여행 (0) | 2017.05.26 |
Comments