// 2504 괄호의 값 -못품 ㅠ
// stack<int> s;
// 괄호는 안쓰는 값으로 -> -1
#include <bits/stdc++.h>
using namespace std;
string str;
int res;
stack<string> st;
void check(void){
for(int i=1; i<st.size(); i++){
if (st[i] == ')'){
if (st[i-1] == '('){
st[i-1] = '2';
st.pop();
}
}
if (st[i] == ']'){
if (st[i-1] == '['){
st[i-1] = '3';
st.pop();
}
}
}
for(string s: st) cout << s;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> str;
//str.replace(str.begin(), str.end(), "()", "2");
//str.replace(str.begin(), str.end(), "[]", "3");
for(int i=0; i<str.size(); i++){
st.top()
st.push(str[i]);
// 스택에 입력시마다 체크
check();
// ( 들어오면 ) 닫혔는지 확인 -> 맞으면 2
// [ 들어오면 ] 닫혔는지 확인 -> 맞으면 3
}
//cout << ans;
return 0;
}
코딩캠프