|
|
вернуться в форумAnybody knows about MLE#10 Послано gt11 23 июн 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; } Re: Anybody knows about MLE#10 Послано gt11 23 июн 2009 03:12 OMG. Changed iostream on stdio.h and it got accepted!! :) 713kb OMG OMG OMG |
|
|