QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314192#7894. Many Many HeadsMaverikRE 0ms0kbC++231.0kb2024-01-25 14:06:172024-01-25 14:06:18

Judging History

你现在查看的是最新测评结果

  • [2024-01-25 14:06:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-01-25 14:06:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e6+10;
char res[maxn];
inline void solve()
{
    string str; cin>>str;
    vector<char>stk;
    for(int i=0;i<(int)str.size();i++)
    {
        char s=str[i]; res[i]=s;
        if(stk.empty()){ stk.push_back(res[i]); continue; }

        char pres=stk.back();
        if(s=='(')
        {
            if(pres=='(') stk.pop_back(),res[i]=')';
            else stk.push_back(s); 
        }
        else if(s==')')
        {
            if(pres=='(') stk.pop_back();
            else res[i]='(',stk.push_back(res[i]);
        }
        else if(s=='[')
        {
            if(pres=='[') stk.pop_back(),res[i]=']';
            else stk.push_back(s); 
        }
        else if(s==']')
        {
            if(pres=='[') stk.pop_back();
            else res[i]='[',stk.push_back(res[i]);
        }
    }
    assert(stk.empty());
}
signed main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);
    int T;cin>>T;while(T--) solve();
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:


result: