?? abcd.cpp
字號:
#include <stdio.h>
#include <malloc.h>
#define MaxSize 100
int Match(char *exp)
{
struct
{
int data[MaxSize];
int top; /*棧指針*/
} st;
st.top=-1;
while(*exp!='\0')
{
if (*exp=='('||*exp=='['||*exp=='{')
{st.top++;st.data[st.top]=*exp;
}
if (*exp==')')
if(st.data[st.top]=='(')
st.top--;
else return 0;
if(*exp==']')
if(st.data[st.top]=='[')
st.top--;
else return 0;
if(*exp=='}')
if(st.data[st.top]=='{')
st.top--;
else return 0;
exp++;
}
return(st.top==-1);
}
void main()
{ char exp[50];
printf("判斷表達式中括弧是否正確配對\n請輸入一個表達式:");
scanf("%s",exp);
if (Match(exp))
printf("該表達式中括弧 配對\n");
else printf("該表達式中括弧 不配對\n");
getchar();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -