알고리즘 문제풀기/인프런 강의 정답
54. 올바른 괄호 (STL stack 자료구조 활용) [정렬 & 이분탐색(결정알고리즘) & 투포인트 알고리즘 & 스택]
코다람쥐
2022. 4. 25. 10:13
나의정답.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int main(int argc, char** argv) {
//freopen("input.txt", "rt", stdin);
stack<char> s;
char c = 'a';
bool no = false;
while (c != 10) {
scanf("%c", &c);
if (c == '(')
s.push(c);
else if (c == ')' && s.empty())
no = true;
else if (c == ')')
s.pop();
}
if (no || !s.empty())
printf("NO");
else
printf("YES");
}