온전한 괄호를 구하는 문제와 동일하다. 온전한 괄호를 구하듯이 온전한 단어 아치를 구하는 문제이다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
void input_voca(vector<string> &voca)
{
int N, i;
string temp;
cin >> N;
for (i = 0; i < N; i++)
{
cin >> temp;
voca.push_back(temp);
}
return;
}
void find_answer(vector<string>& voca)
{
int i, j;
int count = 0;
for (i = 0; i < voca.size(); i++)
{
stack<char> temp;
for (j = 0; j < voca[i].length(); j++)
{
if (temp.empty())
{
temp.push(voca[i][j]);
}
else
{
if (voca[i][j] == temp.top())
{
temp.pop();
}
else
{
temp.push(voca[i][j]);
}
}
}
if (temp.empty())
{
count++;
}
}
cout << count << "\n";
return;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<string> voca;
input_voca(voca);
find_answer(voca);
return 0;
}