符号配对
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<char> stk;
string str;
while (getline (cin , str))
{
if (str == ".")
{
break;
}
for (int i = 0;i < str.length ();i ++)
{
if (str[i] == '(' || str[i] == '[' || str[i] == '{')
{
stk.push (str[i]);
}
else if (str[i] == '/' && str[i + 1] == '*')
{
stk.push ('<');
i ++;
}
else if (str[i] == ')' || str[i] == ']' || str[i] == '}')
{
if (stk.empty ())
{
cout << "NO" <<endl;
cout << "?-" << str[i];
return 0;
}
char c = stk.top ();
stk.pop ();
if (str[i] == ')' && c != '(' || str[i] == ']' && c != '[' || str[i] == '}' && c != '{')
{
cout << "NO" <<endl;
if (c == '<')
cout << "/*-?";
else
cout << c << "-?";
return 0;
}
}
else if (str[i] == '*' && str[i + 1] == '/')
{
if (stk.empty ())
{
cout << "NO" <<endl;
cout << "?-*/";
return 0;
}
char c = stk.top ();
stk.pop ();
i ++;
if (c != '<')
{
cout << "NO" <<endl;
cout << c << "-?";
return 0;
}
}
}
}
if (stk.empty ())
cout << "YES" <<endl;
else
{
char c = stk.top ();
stk.pop ();
if (c != '<')
{
cout << "NO" <<endl;
cout << c << "-?";
return 0;
}
else
{
cout << "NO" <<endl;
cout << "/*-?";
return 0;
}
}
return 0;
}