-
https://www.acmicpc.net/problem/9012
9012번: 괄호
괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고
www.acmicpc.net
#include <stack> #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int testCase; cin >> testCase; for (int i = 0; i < testCase; i++) { string strVPS; cin >> strVPS; stack<char> temp; for (int j = 0; j < strVPS.size(); j++) { if (temp.empty() || strVPS[j] == '(') temp.push(strVPS[j]); else if (temp.top() == '(') temp.pop(); } temp.empty() ? cout << "YES \n" : cout << "NO \n"; } return 0; }
'코딩 테스트 > 백준' 카테고리의 다른 글
10845 큐 (0) 2022.02.12 1406 에디터 (0) 2022.02.11 1874 스택 수열 (0) 2022.02.10 9093 단어 뒤집기 (0) 2022.02.08 10828 스택 (0) 2022.02.07