QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314194#7894. Many Many HeadsMaverikWA 0ms3520kbC++231.2kb2024-01-25 14:09:132024-01-25 14:09:13

Judging History

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

  • [2024-01-25 14:09:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3520kb
  • [2024-01-25 14:09:13]
  • 提交

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())
        {
            if(s==')') stk.push_back(res[i]='(');
            else if(s==']') stk.push_back(res[i]='[');
            else 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]);
        }
    }
    // for(auto x:stk) cout<<x<<" ";cout<<endl;
    assert(stk.empty());
}
signed main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);
    int T;cin>>T;while(T--) solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3520kb

input:

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

output:


result:

wrong answer Answer contains longer sequence [length = 6], but output contains 0 elements