문제: 3986번: 좋은 단어
basic-algo-lecture/workbook/0x08.md at master · encrypted-def/basic-algo-lecture
basic-algo-lecture/workbook/0x08.md at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip> // setprecision을 사용하기 위한 헤더
#include <climits>
#include <list>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int cnt = 0;
for (int i = 0; i < n; i++) {
string word;
cin >> word;
stack<char> s;
for (int j = 0; j < word.size(); j++) {
if (s.empty() || s.top() != word[j])
s.push(word[j]);
else if (s.top() == word[j])
s.pop();
}
if (s.empty())
cnt++;
}
cout << cnt << "\n";
return 0;
}
참고자료:
BaaaaaaaarkingDog | [실전 알고리즘] 0x08강 - 스택의 활용(수식의 괄호 쌍)
[실전 알고리즘] 0x08강 - 스택의 활용(수식의 괄호 쌍)
안녕하세요, 0x05강에서 스택을 다룰 때 후반부에 얘기를 하기도 했었지만 스택의 대표적인 활용 사례로 수식의 괄호 쌍이랑 전위/중위/후위 표기법, DFS, Flood Fill 등이 있습니다. 이 중에서 전위/
blog.encrypted.gg