본문 바로가기

PS

백준 3986 C++ [boj 3986 좋은 단어]

#include <bits/stdc++.h>
using namespace std;

int ans;

void solve() {
    string str;
    cin >> str;
    stack<char> st;
    for (size_t i = 0; i < str.length(); ++i) {
        if (!st.empty() && st.top() == str[i]) {
            st.pop();
        } else {
            st.push(str[i]);
        }
    }
    if (st.empty()) {
        ans++;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    while (n--) {
        solve();   
    }
    cout << ans << '\n';
    return 0;
}