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 Erro?

Posted by adamgic at 2005-04-01 03:28:28 on Problem 1068
#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:
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