文章

12

粉丝

10

获赞

0

访问

1.8k

头像
括号匹配 题解:画两个栈演示一下可能会比较形象
P1501 西北工业大学2015机试题
发布于2024年3月18日 17:42
阅读数 167

#include<iostream>
#include<stack>
#include<cstring>

using namespace std;

stack<char> s1,s2;

bool Judge(char a,char b)
{
    if(a=='('&&b==')')
        return true;
    if(a=='['&&b==']')
        return true;
    return false;
}
int main()
{
    char A[1024];
    cin>>A;
    for(int i = 0;i<strlen(A);i++)
    {
        s1.push(A[i]);
        //cout<<s1.top();    
    }
    //cout<<endl;

    if(strlen(A)%2)//括号个数为奇数直接判错!
    {
        cout<<"NO";  
        return 0;
   ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发