| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
还是runtime error,郁闷,到底哪儿错了啊?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator