The Balance of the World Aizu - 1173

题目链接:https://vjudge.net/problem/Aizu-1173

题解:简单模拟一下过程就好了。

AC代码:

#include<iostream>
#include<stack>
#include<vector>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
    string C;
    while (1)
    {
        stack<char>S;
        getline(cin, C);
        if (C[0] == '.')
            break;
        else
        {
            int ant = 0;
            for (int i = 0; i < C.length(); ++i)
            {
                if (C[i] == '(' || C[i] == '[')
                    S.push(C[i]);
                else if (C[i] == ')')
                {
                    if (!S.empty() && S.top() == '(')
                        S.pop();
                    else 
                        ant = 1;
                }
                else if (C[i] == ']')
                {
                    if (!S.empty() && S.top() == '[')
                        S.pop();
                    else
                        ant = 1;
                }
                if (ant)
                    break;
            }
            if (!ant && S.empty())
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        }
    }
    return 0;
}

今天也是元气满满的一天!good luck! 

猜你喜欢

转载自www.cnblogs.com/cattree/p/9379653.html