https://www.acmicpc.net/problem/10828
그리 어려운 문제는 아니고 라이브러리 쓰는 방법을 블로그에 저장용.
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 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <stack> #include <string> using namespace std; int main() { int N; stack<int> stack1; cin >> N; for (int i = 0; i < N; i++) { string str; cin >> str; if (str == "push") { int a; cin >> a; stack1.push(a); } else if (str == "top") { if (stack1.empty() == 1) cout << "-1" << endl; else cout << stack1.top() << endl; } else if (str == "size") cout << stack1.size() << endl; else if (str == "empty") cout << stack1.empty() << endl; else if (str == "pop") { if (stack1.empty() == 1) { cout << "-1" << endl; } else { cout << stack1.top() << endl; stack1.pop(); } } } return 0; } | cs |
'Algorithm Problems > BOJ' 카테고리의 다른 글
[10809번] 알파벳 찾기 - String[C++] (1) | 2017.03.15 |
---|---|
[10808번] 알파벳 개수 - string[C++] (0) | 2017.03.13 |
[10953번] A+B(6) - 사칙연산[C++] (0) | 2017.03.13 |
[11722번] 가장 긴 감소하는 부분 수열 - LIS & DP[C++] (0) | 2017.03.06 |
[11053번] 가장 긴 증가하는 수열 - LIS & DP[C++] (0) | 2017.03.06 |