백준 문제풀이

백준 4949번 - C++

diligent_gideok 2022. 4. 30. 06:26
#include <bits/stdc++.h>
using namespace std;

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	while (1) {
		int flag = 0;
		string s;
		getline(cin, s);
		if (s == ".") break;
		stack<char> S;
		for (auto c : s) {
			if (c == '(' || c == '[') S.push(c);
			else if (c == ')') {
				if (!S.empty() && S.top() == '(') S.pop();
				else {
					flag = 1;
					break;
				}
			}
			else if (c == ']') {
				if (!S.empty() && S.top() == '[') S.pop();
				else {
					flag = 1;
					break;
				}
			}

			if (S.empty() && c == '.') {
				cout << "yes" << '\n';
			}
		}
		if (!S.empty() || flag == 1) cout << "no" << '\n';
	}
}

'백준 문제풀이' 카테고리의 다른 글

백준 1012번 - C++  (0) 2022.04.30
백준 10799번 - C++  (0) 2022.04.30
백준 11003번 - C++  (0) 2022.04.30
백준 10866번 - C++  (0) 2022.04.30
백준 5430번 - C++  (0) 2022.04.30