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

还是runtime error,郁闷,到底哪儿错了啊?

Posted by hoho at 2003-10-16 13:07:53 on Problem 1068
#include<stdio.h>
#include<stdlib.h>
void convert(int *num,int n)
{
	int k=0,*arr=(int *)malloc(n);
	char *brac=(char *)malloc(2*n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=num[i]-num[i-1];j++)
			brac[k++]='(';
		brac[k++]=')';
	}
	int stack[21],jj=0,top=-1;
	for(int ii=0;ii<2*n;ii++)
		if(brac[ii]=='(')
			stack[++top]=ii;
		else
		{
			arr[jj++]=(ii-stack[top]+1)/2;
			top--;
		}
	for(k=0;k<n-1;k++)
		printf("%d ",arr[k]);
	printf("%d\n",arr[k]);
}
int main()
{
	int testcase,n,i,j,*num=NULL;
	scanf("%d",&testcase);
	for(i=0;i<testcase;i++)
	{
		scanf("%d",&n);
		num=(int *)malloc(n+1);
		num[0]=0;
		for(j=1;j<n;j++)
			scanf("%d ",&num[j]);
		scanf("%d",&num[j]);
		convert(num,n);
	}
	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