QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561937 | #7525. Brackets | ucup-team052# | WA | 1ms | 5760kb | C++23 | 792b | 2024-09-13 13:20:18 | 2024-09-13 13:20:18 |
Judging History
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;
}
详细
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