| ||||||||||
| 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 Erro?#include <iostream>
#include <malloc.h>
#include <stack>
using namespace std;
class Node{
public:
int value;
int pos;
Node(int v,int p){value=v;pos=p;}
};
int main(void)
{
int cases;
int count;
int *source;
cin>>cases;
for(int i=0;i<cases;i++)
{
int size=1;
int index=0;
int left=0;
source=(int*)malloc(sizeof(int)*size);
cin>>count;
for(int j=0;j<count;j++)
{
int s;
cin>>s;
size+=s;
realloc(source,sizeof(int)*size);
int dec=s-left;
for(int x=0;x<dec;x++)
{
source[index++]=1;
left++;
}
source[index++]=0;
} //the input work is done with the length of the array(index)
stack<Node> vint;
vint.push(Node(1,0));
for(int i=1;i<index;i++)
{
int rightcount=0;
if(vint.top().value!=source[i]){
source[i]=2;
for(int i=vint.top().pos;i<index;i++)
if(source[i]==2)++rightcount;
cout<<rightcount<<" ";
vint.pop();
}
else
vint.push(Node(source[i],i));
}
cout<<endl;
free(source);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator