UVA 673

来源:互联网 发布:淘宝网领券猫腻 编辑:程序博客网 时间:2024/04/30 03:39

一个渣到爆的菜鸡,就是一个模拟栈的操作,调试了这么长时间。

/*************************************************************************      > File Name: Parentheses Balance UVA - 673      > Author: Mrhanice      > Mail: 690697134@qq.com      > Created Time: 20170311      > link : https://vjudge.net/problem/UVA-673  ************************************************************************/#include <cstdio>#include <cstring>#include <stack>using namespace std;const int maxn=200;int main(){    int t;    scanf("%d",&t);    getchar();    while(t--)    {        stack <char> par;        char str[maxn];        gets(str);        int len=strlen(str),flag=1;        for(int i=0; i<len; i++)        {            if(str[i]=='('||str[i]=='[')            {                par.push(str[i]);            }            else            {                if(par.empty())                {                    flag=0;                    break;                }                else                {                    if(str[i]==')'&&par.top()=='(')                    {                        par.pop();                    }                    else if(str[i]==']'&&par.top()=='[')                    {                        par.pop();                    }                    else                    {                        flag=0;                        break;                    }                }            }        }        if(flag&&par.empty())            printf("Yes\n");        else printf("No\n");    }    return 0;}


0 0