728x90
반응형
솔루션
해당 문제는 ABBA -> AA -> 빈 이런식으로 짝이 맞는 단어가 없어지면 좋은 단어라고 판별하는 문제이다. 빈 스택을 만들어서 해당 두 단어를 비교한후 없애주는 방식으로 코드를 작성했다.
#include<iostream>
#include<vector>
using namespace std;
int n;
void pop_code(vector<char>& c)
{
if (c.size() > 1)
{
if (c[c.size() - 1] == c[c.size() - 2])
{
c.pop_back();
c.pop_back();
}
}
}
int main(void)
{
int cnt = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
string str;
cin >> str;
vector<char> temp;
for (int j = 0; j < str.size(); j++)
{
temp.push_back(str[j]);
pop_code(temp);
}
if (temp.size() == 0)
{
cnt++;
}
}
cout << cnt;
return 0;
}
728x90
반응형
'알고리즘' 카테고리의 다른 글
파이(π)를 구하는 몬테카를로 시뮬레이션 (Monte Carlo Simulation) (0) | 2025.06.25 |
---|---|
[BOJ-1940] C++ 주몽 / 실버4 (1) | 2024.12.11 |
[BOJ-1213] C++ 팰린드롬 만들기 / 실버3 (0) | 2024.12.11 |
[프로그래머스 - C++] 야근 지수 (0) | 2024.12.04 |
[종만북 예제 P150] 보글 게임 전체코드 (1) | 2024.12.04 |