可以帮我解答一下吗?
#include<iostream>
#include<stack>
using namespace std;
int main()
{
stack<char> stk;
char s[] = "[{()}]";
bool flag = true;
int i = 0;
while (s[i] != '\0')
{
if (s[i] == '(' || s[i] == '[' || s[i] == '{')
stk.push(s[i]);
else if (s[i] == '}')
{
if (stk.top() == '{' && !stk.empty())
{
stk.pop();
}
else
{
cout << "无法匹配!" << endl;
flag = false;
break;
}
}
else if (s[i] == ']')
{
if (stk.top() == '[' && !stk.empty())
{
stk.pop();
}
else
{
cout << "无法匹配!" << endl;
flag = false;
break;
}
}
else if (s[i] == ')')
{
if (stk.top() == '(' && !stk.empty())
{
stk.pop();
}
else
{
cout << "无法匹配!" << endl;
flag = false;
break;
}
}
}
if (flag==true&&stk.empty())
{
cout << "括号匹配成功!" << endl;
}
else
{
cout << "括号匹配不成功!" << endl;
}
}