ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1220. Stacks

Crash(acsses violation) on 3test
Posted by [USU]And_IV[КБ-101] 4 Dec 2008 14:54
why???
#include <iostream>
//#include <stdlib.h>
//#include <stdio.h>
#include <string.h>
using namespace std;
int i,o,tp,nm;
struct Tpart
{
    int val [24];
    int k;
    Tpart *lst;

};
char com[100];
Tpart stk[1024];
int Pop(Tpart *p)
{
    if(p->k>0) return p->val[--(p->k)];
    else
    {
        Tpart *e=p;
    p=p->lst;
    delete e;
    return p->val[--(p->k)];
    }};
void Push(Tpart *p, int val)
{
    if((p->k)<24) (p->val)[(p->k)++]=val;
        else
    {
        Tpart *uk= new Tpart;
        uk->lst=p;
        p=uk;
        p->k=0;
        (p->val)[(p->k)++]=val;
        }
    return;
}
int main() {

    int n; cin>>n;
    for(int j=0;j<n;j++)
    {
        cin>>com;
        if (strcmp(com,"PUSH")==0)
        {
            cin>>nm>>tp;
            Push(&stk[nm-1],tp);
            }
        if (strcmp(com,"POP")==0)
                {
                    cin>>nm;
                    cout<<Pop(&stk[nm-1])<<endl;}
        }
    return 0;
}
Re: Crash(acsses violation) on 3test
I've this problem too((