Coding Test - cpp/String
[백준 9012: 괄호] - C++
에드윈H
2021. 2. 19. 15:37
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore();
string input;
for (int i = 0; i < n; i++)
{
int num = 0;
bool IsFail = false;
cin >> input;
int size = input.size();
for (int j = 0; j < size; j++)
{
if (input[j] == '(')
{
num++;
}
else if (input[j] == ')' && num > 0)
{
num--;
}
else
{
IsFail = true;
}
}
if (IsFail || num != 0)
cout << "NO" << "\n";
else if (num == 0)
{
cout << "YES" << "\n";
}
}
return 0;
}