poj1068

#include<iostream>
#include<cstring>
int num[25],result[25];
char s[150];
int main()
{
	using namespace std;
	int n,m;
	cin >> n;
	while(n--){
		cin >> m;
		for(int i=0;i<m;++i)
			cin >> num[i];
		int ans=0;
		int t=0;
		for(int i=0;i<m;++i){
			if(ans!=num[i]){
				int c=num[i]-ans;for(int j=t;j<t+c;++j)	s[j]='(';
				t+=c;s[t]=')';++t;ans=num[i];
			}
			else{
				s[t]=')';++t;
			}
		}
		int tot=0;ans=0;
		for(int i=0;i<t;++i){
			if(s[i]==')'){
				++tot;
				int you=1;
				for(int j=i-1;j>=0;j--){
					if(s[j]==')')	++you,++tot;
					else if(s[j]=='(')	--you;
					if(!you)	break;
				}
				result[ans++]=tot;
				tot=0;
			}
		}
		for(int i=0;i<ans-1;++i)
			cout << result[i] << " ";
			cout << result[ans-1] << endl;
	}
}

  

posted @ 2016-01-06 23:18  我不萌、我要高冷  阅读(219)  评论(0编辑  收藏  举报