|
|
вернуться в форумUsing C++ STL gives Memory access Runtime Error #include<bits/stdc++.h> using namespace std; int main(){ long N,i,stack_id,num; string code; const string push="PUSH"; vector< stack<int> > stacks; cin>>N; for(i=0;i<N;i++){ cin>>code; if(code==push){ cin>>stack_id>>num;
if(stack_id>stacks.size()){ stacks.push_back( stack<int>() ); } stacks[stack_id-1].push(num);
} else{ cin>>stack_id; cout<<stacks[stack_id-1].top()<<"\n"; stacks[stack_id-1].pop(); } }
return 0; } I get correct output on the sample code though. Re: Using C++ STL gives Memory access Runtime Error Try test: 1 push 900 1 Btw, have you seen memory limit for this task? You need to be able to execute 100,000 pushes of 4-bytes integers (in one stack and in random stacks) - 400 Kb of data + empty program requires ~200K. Your implementation should fail (memory limit) during vector resize. |
|
|