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 |
哪位大哥帮忙看看或给组测试数据。。为啥就“Wrong answer"呢??代码如下:#include<iostream> #include<string> using namespace std; class stack {private: string array[20]; int size; int top; public: stack(int n) {top=0; size=n; } ~stack() {} bool push(string &ch) { if(top==size) return 0; array[top++]=ch; return 1; } bool pop(string tt,string &ch) { if(top==1) { cout<<"Ignored"<<endl; return 1; } if(tt=="BACK") cout<<array[top-2]<<endl; else cout<<array[top-1]<<endl; ch=array[--top]; return 0; } }; int main() {stack A(20),B(20); string sign="http://www.acm.org/"; A.push(sign); while(1) {cin>>sign; if(sign=="QUIT") return 0; string key; if(sign=="VISIT") { string Webname; cin>>Webname; cout<<Webname<<endl; A.push(Webname); } else if(sign=="BACK") { if(!A.pop(sign,key)) B.push(key); } else { 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