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

Why would this fail test 1
Posted by ElPsyCongroo 21 Jun 2014 12:14
#include<vector>
#include<stack>
#include<iostream>
int main()
{
    int noOfInstructions = 0;
    std::cin>> noOfInstructions;

    std::vector< std::stack< int > > myVectorOfStacks;
    myVectorOfStacks.reserve( 1001 );
    for( int inx = 0; inx < 1001; ++inx )
    {
         myVectorOfStacks.push_back( std::stack<int>() );
    }

    char instruction[3];
    int stackNumber = 0;
    int stackValue = 0;

    for( int inx = 0; inx < noOfInstructions; ++inx )
    {
        std::cin>> instruction;

        std::cin>> stackNumber;
        std::stack< int > & tempStack = myVectorOfStacks.at( stackNumber );

        if( instruction[1] == 'U' )
        {
            std::cin>> stackValue;
            tempStack.push( stackValue );
        }
        else
        {
             std::cout<< tempStack.top()<< "\n";
             tempStack.pop();
        }
    }

    return 0;
}