Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

代码虽然难看 还是想贴贴

Posted by 19871026 at 2009-08-12 16:56:46 on Problem 1068
#include<iostream>
using namespace std;
int main()
{
	int t,n,i,j,k,m,l,h,x,q,p[50],f[50],con;
	char yy[50]={'0'};
	cin>>t;
	while(t--)
	{
		cin>>n;
		k=0;m=0;
		memset(f,0,sizeof(f));
		for(i=0;i<n;i++)
		{
			cin>>p[i];
			l=p[i]-m;
			for(j=k;j<k+l;j++)
			{
				yy[j]='(';
				f[j]=1;
			}
			yy[k+l]=')';
			k=k+l+1;
			m=p[i];
		}
		q=strlen(yy);
		for(h=1;h<q;h++)
		{
			con=1;
			if(yy[h]==')')
			{
				for(x=h-1;x>=0;x--)
				{
					if(yy[x]=='('&&f[x]==1)
					{
						f[x]=0;
						cout<<con<<" ";
						break;
					}
					if(yy[x]=='('&&f[x]==0)
						con++;
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator