??
字號:
#include"SqStack.h"
#include<stdio.h>
//括號匹配與否的檢驗,要求表達式中只有兩種括號[]和()
int check(){
SqStack S; //存放括號
SElemType e;
InitStack(S);//棧的初始化;
char c; //存放輸入的字符;
while((c=getchar())!='\n'){
if(c=='('||c=='[') Push(S,c); //如果是左括號就進棧
else if(c==')'){
if(!GetTop(S,e)) return FALSE;//如果棧空,就返回FALSE
if(e=='(')
Pop(S,e); //退棧
else if(e=='[')
return FALSE;
}//else if
else if(c==']'){
if(!GetTop(S,e)) return FALSE;
if(e=='[')
Pop(S,e);
else if(e=='(')
return FALSE;
}//else if
else
continue;
}//while
if(StackEmpty(S)) //如果棧空就真確,否則表達式中還有左括號還沒有被匹配;
return OK;
else
return FALSE;
}
void main()
{
if(check()) cout<<"Yes"<<endl;
else cout<<"NO"<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -