#include "stdio.h"
#include "string.h"
int main()
{
int n,cas,i,j,p[25],w[25],right,left,temp,cnt;
char s[100];
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(i=0; i<n; i++) scanf("%d",&p[i]);
cnt=0;
right=0;
for(i=0; i<n; i++)
{
temp=p[i];
if(right<temp)
{
for(j=right; j<temp; j++)
{
s[cnt]='(';
cnt++;
}
right=temp;
s[cnt]=')';
cnt++;
}
else
{
s[cnt]=')';
cnt++;
}
}
s[cnt]=0;
temp=0;
for(i=0; i<n; i++)
{
for(j=temp;j<2*n;j++)
if(s[j]==')') break;
temp=j+1;
cnt=1;
right=1;
for(j=temp-2;j>=0;j--)
{
if(s[j]=='(')
{
right--;
if(right==0) {w[i]=cnt;break;}
}
if(s[j]==')')
{cnt++;right++;}
}
}
for(i=0; i<n-1; i++)
printf("%d ",w[i]);
printf("%d\n",w[n-1]);
}
return 0;
}
zoj 1016 Parencodings
最新推荐文章于 2021-03-11 05:36:25 发布