[C++]伯俊10828:スタック
8179 ワード
#include <iostream>
#include <stack> // stl 스택
using namespace std;
int main(void){
int N, num;
stack<int> stack; // 스택 선언
string str;
scanf("%d", &N);
for(int i = 0; i < N; i++){
cin >> str;
if(str == "push"){
scanf("%d", &num);
stack.push(num);
} else if(str == "pop"){
if(stack.empty()){
printf("-1\n");
} else {
cout << stack.top() << endl;
stack.pop();
}
} else if(str == "size"){
cout << stack.size() << endl;
} else if(str == "empty"){
if(stack.empty()){
printf("1\n");
} else {
printf("0\n");
}
} else if(str == "top"){
if(stack.empty()){
printf("-1\n");
} else {
cout << stack.top() << endl;
}
}
}
return 0;
}
今日のポイント
Reference
この問題について([C++]伯俊10828:スタック), 我々は、より多くの情報をここで見つけました https://velog.io/@lamknh/C-백준-10828-스택テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol