QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314194 | #7894. Many Many Heads | Maverik | WA | 0ms | 3520kb | C++23 | 1.2kb | 2024-01-25 14:09:13 | 2024-01-25 14:09:13 |
Judging History
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