티스토리 뷰
Code
#include <iostream>
using namespace std;
#define MAX 1000000
int arr[MAX], point;
class stack
{
public:
void push(int data)
{
arr[point++] = data;
}
void pop()
{
cout << arr[point - 1] << "\n";
arr[point - 1] = 0;
point--;
}
int size()
{
return point;
}
bool empty()
{
if (point == 0)
return true;
else
return false;
}
void top()
{
if (point <= 0)
cout << -1 << "\n";
else
cout << arr[point - 1] << "\n";
}
};
int main()
{
stack s;
string command;
int count = 0;
cin >> count;
while (count--)
{
cin >> command; // 명령어 입력
if (command == "push")
{
int data = 0;
cin >> data;
s.push(data);
}
else if (command == "pop")
{
if (s.empty() == 1)
cout << -1 << endl;
else
s.pop();
}
else if (command == "size")
{
cout << s.size() << "\n";
}
else if (command == "empty")
{
cout << s.empty() << "\n";
}
else if (command == "top")
{
s.top();
}
}
}
'프로그래밍 > BOJ' 카테고리의 다른 글
백준 알고리즘 [1152번] (C++) 단어의 개수 (0) | 2022.07.19 |
---|---|
백준 알고리즘 [25083번] (C++) 새싹 (0) | 2022.07.18 |
백준 알고리즘 [2292번] (C++) 벌집 (0) | 2019.08.06 |
백준 알고리즘 [2839번] (C++) 설탕 배달 (0) | 2019.08.05 |
백준 알고리즘 [1712번] (c++) 손익분기점 (0) | 2019.08.05 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 단어의 개수
- 데이터저장장치
- cin.getline()
- toy cipher
- 파일입출력
- 토이사이퍼
- 운영체제
- 웹 어플리케이션 서버
- 웹 서버
- stringstream
- 자료구조
- 25083
- to_string
- 문자열입력
- ??!
- 알고리즘
- web application server
- boj
- 1152
- 커널
- 네트워크결합스토리지
- 쉘
- 백준알고리즘
- C++
- 트리만들기
- getline()
- 정수
- Web Server
- 정수를 문자열로
- 백준
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
글 보관함