文章
9
粉丝
126
获赞
11
访问
51.5k
新手
#include <iostream>
using namespace std;
#include <string.h>
#include <stack>
char s[260];
stack <char> st;
int main ()
{
int n;
scanf ("%d", &n);
for (int j = 0; j < n; j++)
{
int flag = 0;//标记
scanf ("%s", s);
int len = strlen(s);
for (int i = 0; i < len; i++)
{
if (!st.empty() )
{
char now = st.top() ;
if ( now == '<' && s[i] != '<' && s[i] != '>'
|| now == '(' && s[i] != '(' && s[i] != ')' && s[i] != '<' && s[i] != '>'
|| now == '[' && (s[i] == '{' || s[i] == '}'))//优先级问题
{
flag = 1;//当优先级顺序出现问题时,标记为1,输出NO
break;
}
else if (now == '(' && s[i] == ')' || now == '[' && s[i] == ']'
|| now == '{' && s[i] == '}' || now == '<' && s[i] == '>')//匹配问题
st.pop() ;
else st.push(s[i]) ;
}
else st.push(s[i...
登录后发布评论
暂无评论,来抢沙发