https://www.acmicpc.net/problem/5397
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <iostream> #include <cstring> #include <string> #include <stack> #pragma warning (disable : 4996) using namespace std; int main() { int N; string input; stack<char> stack1, stack2; cin >> N; for (int i = 0; i < N; i++) { cin >> input; int size1 = input.size(); for (int j = 0; j < size1; j++) { if (input[j] == '<') { if (stack1.empty() == 0){ char a; a = stack1.top(); stack1.pop(); stack2.push(a); } } else if (input[j] == '>') { if (stack2.empty() == 0){ char a; a = stack2.top(); stack2.pop(); stack1.push(a); } } else if (input[j] == '-') { if (stack1.empty() == 0) stack1.pop(); } else stack1.push(input[j]); } if (stack1.size() > 0){ size1 = stack1.size(); for (int j = 0; j < size1; j++) { char a; a = stack1.top(); stack1.pop(); stack2.push(a); } } int size = stack2.size(); for (int j = 0; j < size; j++) { char a; a = stack2.top(); stack2.pop(); cout << a; } cout << endl; } return 0; } | cs |
'Algorithm Problems > BOJ' 카테고리의 다른 글
[9935번] String Explosion 문자열 폭발 - Stack[C++] ☆ (0) | 2017.01.03 |
---|---|
[1158번] Josephus Problem 조세퍼스 - Deque [C++] ☆ (0) | 2017.01.03 |
[10817번] Three Interger 세 수 - if condition[C++] (0) | 2017.01.02 |
[11721번] Print out per ten lines 열개씩 끊어 출력하기 - For Loop [C++] ☆ (0) | 2016.12.29 |
[1924번] In 2007 2007년 - For Loop [C++] ☆ (0) | 2016.12.28 |