반응형
#include <iostream>
#include <vector>
using namespace std;
class CheckStr
{
public:
CheckStr(string str) : _str(str)
{
int len = _str.length();
int nL = 0;
int nR = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == ')')
{
nR++;
if (nL < nR)
{
isOperate = false;
return;
}
}
if (str[i] == '(')
nL++;
}
if (nL == nR)
isOperate = true;
}
public:
string _str;
bool isOperate = false;
};
int main()
{
int N = 0;
string str = "";
vector<CheckStr> v;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> str;
v.push_back(CheckStr(str));
}
for (int i = 0; i < N; i++)
{
if (v[i].isOperate == true)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
반응형
LIST
'알고리즘 문제 > 백준' 카테고리의 다른 글
[C++] 큐 - 10845 (0) | 2022.11.16 |
---|---|
[C++] 스택 수열 - 1874 (0) | 2022.11.14 |
[c++] 덩치 - 7568 (0) | 2022.11.13 |
[ C++ ] 단어 뒤집기 - 9093 (0) | 2022.11.12 |
[ C++ ] 별 찍기 10 - 2447 (0) | 2022.11.11 |