프로그래밍/문제풀이

백준 3986(좋은 단어)

하용권 2018. 10. 20. 17:11

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



스택으로 짜면 쉬울 거 같아 짜봤습니다.



#include <iostream>
#include <stack>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int N,ret = 0;
cin >> N;
for(int i= 0; i< N; i++){
string str;
stack<char> st;
cin >> str;
for(int j = 0; j < str.length(); j++){
if(!st.empty()&&st.top() == str[j])st.pop();
else st.push(str[j]);
}
if(st.empty()) ret+=1;
}
cout << ret;
}


반응형