Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:哪位大哥帮忙看看或给组测试数据。。为啥就“Wrong answer"呢??代码如下:In Reply To:哪位大哥帮忙看看或给组测试数据。。为啥就“Wrong answer"呢??代码如下: Posted by:wrp at 2009-11-22 19:18:14 第二次VISIT的时候忘记CLEAR B栈了。 #include<iostream> #include<string> using namespace std; class stack {private: string array[400]; int size; int top; public: stack(int n) {top=0; size=n; } ~stack() {} void clear() //加个clear函数 { top=0; } bool push(string &ch) { if(top==size) return 0; array[top++]=ch; return 1; } bool pop(string tt,string &ch) { if(tt=="BACK") { if(top==1) { cout<<"Ignored"<<endl; return 1; } cout<<array[top-2]<<endl; } else { if(top==0) { cout<<"Ignored"<<endl; return 1; } cout<<array[top-1]<<endl; } ch=array[--top]; return 0; } }; int main() {stack A(400),B(400); string sign="http://www.acm.org/"; A.push(sign); while(1) {cin>>sign; if(sign=="QUIT") return 0; string key; if(sign=="VISIT") { B.clear(); //清空B栈 string Webname; cin>>Webname; cout<<Webname<<endl; A.push(Webname); } else if(sign=="BACK") { if(!A.pop(sign,key)) B.push(key); } else { if(!B.pop(sign,key)) A.push(key); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator