QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314192 | #7894. Many Many Heads | Maverik | RE | 0ms | 0kb | C++23 | 1.0kb | 2024-01-25 14:06:17 | 2024-01-25 14:06:18 |
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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])