본문 바로가기

BOJ

[백준] 4949번 균형잡힌 세상 c++

#include <bits/stdc++.h>
#include <stack>

using namespace std;
int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	stack<char> s;
	string sentence;
	int error = 0;
	while (1) {
		getline(cin, sentence);
		if (sentence==".") break;
		else {
			for (int i = 0; i < sentence.length(); i++) {
				if (sentence[i] == '(' || sentence[i] == '[') {
					s.push(sentence[i]);
				}
				else if (sentence[i] == ')') {
					if (s.empty() || s.top() != '(') error++;
					else s.pop();

				}
				else if (sentence[i] == ']') {
					if (s.empty() || s.top() != '[') error++;
					else s.pop();
				}
			}	
		}
		if (s.size())cout << "no" << "\n";
		else if (s.size() == 0 && error == 0) cout << "yes" << "\n";	
		else cout << "no" << "\n";
				
		while (!s.empty()) s.pop();
		error = 0;
	}
	return 0;
}

 

진짜 진심으로 풀면서 너무 짜증났던 문제

그냥 내 자신한테도 짜증나고

된 것 같아서 제출하면 틀렸습니다만 계속 나오고

그리고 }}} {{{ 이런것도 생각해야되는지 계속 헷갈리고 그래가지고

시발 그냥 2시간동안 계속 스트레스 받다가 겨우 풀었네

알고보니 처음부터 계속 실수도 했었고

그냥 이거 보면 짜증남 진짜

'BOJ' 카테고리의 다른 글

[백준] 10039번 평균 점수 c++  (0) 2020.04.26
[백준] 9012번 괄호 c++  (0) 2020.04.24
[백준] 2164번 카드2 c++  (0) 2020.04.23
[백준] 4월 23일 실버 달성  (0) 2020.04.23
[백준] 10845번 큐 c++  (0) 2020.04.23