#include "LinkStack.hpp"
#include <iostream>
using namespace std;
int main()
{
LinkStack<char> stack;
cout << "输入带括号的字符串 ((a)(b))" << endl;
char ch;
do
{
cin >> ch;
switch(ch)
{
case '(': stack.Push(ch);
break;
case ')':
if(!stack.IsEmpty())
{
stack.Pop();
break;
}
else
{
cout << "ERROR!" <<endl;
return 0;
}
}
}while(ch!='0'); // 回车 \r 换行 \n
if(!stack.IsEmpty())
{
cout << "ERROR!" << endl;
return 0;
}
else
{
cout << "OK!" << endl;
return 0;
}
}
圆括号匹配
最新推荐文章于 2023-07-07 15:17:08 发布