코딩테스트/백준

[실4] 3986 - 좋은 단어

ShovelingLife 2022. 10. 23. 23:45
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main()
{
    int n, res = 0; cin >> n;
    
    while(n--)
    {
        string str; cin >> str;
        stack<char> s;

        for (int i = 0; i < str.size(); i++)
        {
        	if(!s.empty() &&
                s.top()==str[i])
            {
                s.pop();
                continue;
            }
            s.push(str[i]);
        }
        if (s.empty())
            res++;
    }
    cout << res;
}