https://www.acmicpc.net/problem/3986
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 | #include <stack> #include <stdio.h> #include <iostream> #include <string> using namespace std; int main() { int N; unsigned long long count = 0; cin >> N; for (int i = 0; i < N; i++) { stack<char> stack1; string input; cin >> input; for (int i = 0; i < input.size(); i++) { // method 1 if (!stack1.empty() && input[i] == stack1.top()) stack1.pop(); else stack1.push(input[i]); /* method 2 if (stack1.empty()) stack1.push(input[i]); else { if (input[i] == stack1.top()) stack1.pop(); else stack1.push(input[i]); } */ } if (stack1.empty()) count++; } cout << count; return 0; } | cs |
'Algorithm Problems > BOJ' 카테고리의 다른 글
[11718번] Output as is 그대로 출력하기 - In/Output[C++] (0) | 2016.12.27 |
---|---|
[4673번] Self Number 셀프 넘버 - Method[Java] (0) | 2016.12.22 |
[11718번] Output as is 그대로 출력하기 - In/Output[Java] (0) | 2016.12.22 |
[9012번] Parenthesis 괄호 - Stack[C++] (0) | 2016.12.19 |
[6198번] Bad hair Day - Stack [C++] ☆ (0) | 2016.12.19 |