24分求助
查看原帖
24分求助
855522
封禁用户楼主2023/11/10 22:34
#include <iostream>
#include <stack>
using namespace std; 

stack <char> stk;

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i != s.size(); i++)
    {
        stk.push(s[i]);
    }
    while (!stk.empty())
    {
        char ch = stk.top();
        stk.pop();
        if (ch == ')')
        {
            if (stk.top() == '(')
            {
                stk.pop();
            }
            else
            {
            	cout << "()";
			}
            cout << "()";
        }
        else if (ch == '(')
        {
        	cout << "()";
		}
        else if (ch == ']')
        {
            if (stk.top() == '[')
            {
                stk.pop();
            }
            else
            {
            	cout << "[]";
			}
            cout << "[]";
        }
        else
        {
        	cout << "[]";
		}
    }
    return 0;
}
2023/11/10 22:34
加载中...