백준 문제풀이

백준 2504번 - C++

diligent_gideok 2022. 4. 15. 18:43
#include <bits/stdc++.h>
using namespace std;

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);

	stack<char> S;
	string s;
	cin >> s;
	int n=0,sum=0;
	
	for (auto c : s) {
		if (c == '(') {
			cout << 2 ;
			S.push(c);
		}
		else if (c == ')') {
			if (S.top() == '('||S.top()=='[') {
				cout << " + ";
			}
			else {
				cout << 0;
				return 0;
			}
		}
		else if (c == '[') {
			cout << 3 ;
			S.push(c);
		}
		else if (c == ']') {
			if (S.top() == '['||S.top()=='(') {
				cout << " + ";
			}
			else {
				cout << 0;
				return 0;
			}
		}
		if (S.empty()) {

		}
		

	}

}

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

백준 1919번 - C++  (0) 2022.04.30
백준 1475번 - C+  (0) 2022.04.30
백준 15552번 - C++  (0) 2022.04.12
백준 10871번 - C++  (0) 2022.04.12
백준 10869번 - C++  (0) 2022.04.12