관리 메뉴

풀이 보관함

[C++] 백준 3986번: 좋은 단어 본문

problem solving/백준

[C++] 백준 3986번: 좋은 단어

viin 2022. 7. 3. 00:49

문제

https://www.acmicpc.net/problem/3986

 

 

풀이

 

가장 어려운 것이 문제 이해였다.

 

 

 

소스

#include <iostream>
#include <string>
#include <stack>

int main()
{
    int N = 0, result = 0;
    std::string word;

    std::cin >> N;
    for(int i=0; i<N; ++i)
    {
        std::stack<char> stk;
        std::cin >> word;
        for(auto& c : word)
        {
            if(!stk.empty() && stk.top() == c)
                stk.pop();
            else
                stk.push(c);
        }

        if(stk.empty()) ++result;
    }
    std::cout << result;
    return 0;
}