//比较简单的模拟题,只要还原出原来最初始的括号字符串就很容易得出第二种模式的表示!
#include "iostream"
using namespace std;
int s[50], p[30], w[30];
int main()
{
int tc, n, i, j, k, count;
cin >> tc;
while (tc--)
{
cin >> n;
for (i = 0; i < n * 2; i++)
s[i] = 0;
for (i = 0; i < n; i++)
cin >> p[i];
for (i = 0; i < n; i++)//由p模式得出最原始的括号字符串(即还原出原来的括号字符串)0代表左括号,1代表右括号
{
count = 0;
for (j = 0; j < n * 2; j++)
{
if (count == p[i])
{
while (s[j])
j++;
s[j] = 1;
break;
}
if (s[j] == 0)
count++;
}
}
k = 0;
for (i = 0; i < n*2; i++)//由p模式向w模式的转换!
{
count = 1;
if (s[i] == 1)
{
s[i] = -2;
for (j = i - 1; j >= 0; j--)
{
if (s[j] == -1)
count++;
else if (s[j] == -2) continue;
else
{
s[j] = -1;
w[k] = count;
k++;
break;
}
}
}
}
for (i = 0; i < n; i++)
{
if (i)
cout << " ";
cout << w[i];
}
cout << endl;
}
system("pause");
}
poj 1068 Parencodings
最新推荐文章于 2022-10-09 16:11:21 发布