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

gt11 Anybody knows about MLE#10 [1] // Problem 1220. Stacks 23 Jun 2009 00:58
What's so cool in this test? It pushes a lot into one stack or a lot into many stacks or what?
#include <iostream>
using namespace std;

struct elem
{
    unsigned int value;
    elem * next;
};
elem ** tree;
elem * push(elem * stack,unsigned int value)
{
    if(!stack)
    {
        stack = new elem;
        stack->value = value;
        stack->next = NULL;
        return stack;
    }
    else
    {
        elem * temp = new elem;
        temp->value = value;
        temp->next = stack;
        return temp;
    }
}
elem * pop(elem * stack,unsigned int & value)
{
    elem * temp = stack->next;
    value = stack->value;
    delete stack;
    return temp;
}
int main()
{
    tree = new elem* [1000];
    memset(tree,0,1000*4);
    int n;
    cin>>n;
    char str[5];
    int a;
    unsigned int b;
    for(int i = 0;i<n;++i)
    {
        cin>>str;
        if(str[1]=='U')
        {
            cin>>a;
            cin>>b;
            tree[a-1] = push(tree[a-1],b);

        }
        else
        {
            cin>>a;
            unsigned int value;
            tree[a-1] = pop(tree[a-1],value);
            cout<<value<<endl;

        }
    }

    return 0;
}
gt11 Re: Anybody knows about MLE#10 // Problem 1220. Stacks 23 Jun 2009 03:12
OMG. Changed iostream on stdio.h and it got accepted!! :) 713kb OMG OMG OMG