QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545444#7683. Hard Brackets Problemzzz666WA 1ms4500kbC++20734b2024-09-03 12:59:182024-09-03 12:59:18

Judging History

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

  • [2024-09-03 12:59:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4500kb
  • [2024-09-03 12:59:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+4;
void slove()
{
	string s;
	cin>>s;
	stack<char>sta;
	char ans[N];
	int cnt = 0 ;
	for(int i = 0 ; i < s.size() ; i++)
	{
		if(s[i] == '(')
		{
			sta.push('(');
			continue;
		}
		if(sta.empty() && s[i] == ')')
		{
			ans[++cnt] = ')';
			continue;
		}
		if(!sta.empty() && s[i] == ')')
		{
			ans[++cnt] = '(';
			sta.pop();
			continue;
		}
	}
	while(!sta.empty())
	{
		ans[++cnt] = sta.top();
		sta.pop();
	}
	if(cnt == 0)
	{
		cout<<"impossible"<<endl;
		return;
	}
	for(int i = 1 ; i <= cnt ; i ++ )
	{
		cout<<ans[i]; 
	}
	cout<<endl;
}
int main()
{
	int tcase;
	cin>>tcase;
	while(tcase--)
	{
		slove();
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4500kb

input:

3
((()))
(
)))()

output:

(((
(
)))(

result:

wrong answer the result string is incorrect (test case 2)