<pre name="code" class="cpp">//-------------------------------------------【夜雨蝉鸣】----------------------------------------------
#include <iostream>
#include <stack>
#include <iterator>
using namespace std;
void main()
{
stack<char> mystackda; //大括号
stack<char> mystackxiao; //小括号
stack<char> mystackjian; //尖括号
char s[30]="ABCD{()PPPL<>()}";
char *p=&s[0];
while( (*p)!='\0' ) //遍历字符串s
{
switch(*p)
{
case '{':
mystackda.push('{');
break;
case '}':
if (mystackda.empty())
{
goto over;
}
mystackda.pop();
break;
case '<':
mystackjian.push('<');
break;
case '>':
if (mystackjian.empty())
{
goto over;
}
mystackjian.pop();
break;
case '(':
mystackxiao.push('(');
break;
case ')':
if (mystackxiao.empty())
{
goto over;
}
mystackxiao.pop();
break;
}
p++;
}
if ( mystackda.empty() && mystackjian.empty() && mystackxiao.empty() )
{
cout<<"\n字符匹配"<<endl;
}
else
{
over: cout<<"\n字符不匹配"<<endl;
}
system("pause");
}