POJ 1068 Parencodings 模拟-括号匹配

此题简单。

题目:http://www.acmerblog.com/POJ-1068-Parencodings-blog-254.html

代码如下:

#include<iostream>
using namespace std;

int len = 20;
int Ps[20];
int Ws[20];
bool leftParenFlag[20] = { false };

void main()
{
	int t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;                                               //n<=20
		for (int i = 0; i < len; ++i) leftParenFlag[i] = false; //初始时,全部置为false
		for (int i = 0; i < n; ++i) cin >> Ps[i];               //输入P-sequence
		for (int k = 0; k < n; ++k)                            
			for (int j = Ps[k]-1; j >=0; --j)
			{
				if (!leftParenFlag[j])
				{
					Ws[k] = Ps[k] - j;
					leftParenFlag[j] = true;
					break;
				}
			}
		for (int i = 0; i < n; ++i)cout << Ws[i] << " ";
		cout << endl;	
	}
}


你可能感兴趣的:(C++,函数,poj)