입력:
3
ABAB
AABB
ABBA
출력:
2
백준 3986번 "좋은 단어" 문제의 코드입니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,num;
string a;
cin>>N;
for(int i=0;i<N;i++){
cin>>a;
stack<char> s;
for(int j=0;j<a.length();j++){
if(s.empty()||s.top()!=a[j])
s.push(a[j]);
else if(s.top()==a[j])
s.pop();
}
if(s.empty()) num++;
}
cout<<num;
return 0;
}
위의 코드를 예제의 입력을 넣어 실행했을 때의 결과입니다.
백준 4375 1 C++ (0) | 2023.04.04 |
---|---|
백준 1629 곱셈 C++ (0) | 2023.04.04 |
백준 1002 터렛 C++ (0) | 2023.04.04 |
백준 1940 주몽 C++ (0) | 2023.04.02 |
백준 11170 0의 개수 C++ (0) | 2023.04.02 |