首页 > 其他 > 详细

stack模拟 括号匹配

时间:2015-03-09 14:32:13      阅读:178      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<stack>
using namespace std;
int main()
{
    int ncase,num;
    char str;
    cin>>ncase;
    while(ncase--)
    {
        cin>>num;
        stack<char> st;
        for(int i=0;i<num;i++)
        {
            cin>>str;
            if(!st.empty()&&st.top()=='>'&&str=='<')
            {
                st.pop();
                continue;
            }
            else
                st.push(str);
        }
        if(st.empty()) cout<<"legal\n"<<endl;
        else cout<<"illegal\n"<<endl;
    }
    return 0;
}

stack模拟 括号匹配

原文:http://blog.csdn.net/chaoyueziji123/article/details/44153209

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!