QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561937#7525. Bracketsucup-team052#WA 1ms5760kbC++23792b2024-09-13 13:20:182024-09-13 13:20:18

Judging History

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

  • [2024-09-13 13:20:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5760kb
  • [2024-09-13 13:20:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 1000005
char s[N];
int n,a[N];
char b[N];
int m;
signed main()
{
#ifdef xay5421
	freopen("b.in","r",stdin);
#endif
	scanf("%s",s+1);
	n=strlen(s+1);
	int cur=0;
	string ans;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='+') cur++;
		else
		{
			m++;
			a[m]=cur,cur=0;
			b[m]=s[i];
		}
	}
	a[m+1]=cur;
	assert(a[1]%2==0);
	for(int i=2;i<=m;i++) assert(a[i]%2==1),a[i]--;
	assert(a[m+1]%2==0);
	for(int i=1;i<=m;i++)
	{
		if(i!=1) ans+="+";
		if(a[i]==2)
		{
			if(a[i+1]>=2) a[i+1]-=2,ans+=(string)"((++"+b[i]+")++)";
			else ans+=(string)"(++"+b[i]+")";
		}
		else
		{
			if(a[i+1]>=2) a[i+1]-=2,ans+=(string)"("+b[i]+"++)";
			else ans+=(string)"("+b[i]+")";
		}
	}
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5716kb

input:

x+++y

output:

(x++)+(y)

result:

ok Participant's answer is correct

Test #2:

score: 0
Accepted
time: 1ms
memory: 5760kb

input:

q+u+++h+++++o+q++

output:

(q)+(u++)+(h++)+(++o)+(q++)

result:

ok Participant's answer is correct

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5760kb

input:

++a+++b+++c+++d+e+++f+++g+h+j+k+++++i

output:

((++a)++)+(b++)+(c++)+(d)+(e++)+(f++)+(g)+(h)+(j)+(k++)+(++i)

result:

wrong answer Expression contains more parentheses than variables