#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
char arr[35]={};
scanf("%s",arr);
stack<char> stk;
int fbv=0;
int tp=1;
for(int i=0; arr[i]; i++)
{
if(arr[i]=='(')
{
stk.push('(');
tp*=2;
}
else if(arr[i]=='[')
{
stk.push('[');
tp*=3;
}
else if(!stk.empty() && arr[i]==')' && stk.top()=='(')
{
if(arr[i-1]=='(')
fbv+=tp;
stk.pop();
tp/=2;
}
else if(!stk.empty() && arr[i]==']' && stk.top()=='[')
{
if(arr[i-1]=='[')
fbv+=tp;
stk.pop();
tp/=3;
}
else
{
stk.push(0);
break;
}
}
if(stk.empty())
printf("%d",fbv);
else
printf("0");
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: