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 |
stl 很强大哦主要就是string和stack两个 string中的assign()方法用于赋值 stack中,pop()用于弹出,top()返回最顶上的函数,empty()判断是否为空,push()用于压栈。 这里给出我的代码,请多指教^__^ #include<iostream> #include<string> #include<stack> using namespace std; stack<string> back; stack<string> forward; string operate; string current="http://www.acm.org/"; void backOperate(void); void forwardOperate(void); void visitOperate(string); int main() { back.empty(); forward.empty(); while(cin>>operate) { if(operate == "QUIT") { break; } else if(operate == "VISIT") { string s; cin>>s; visitOperate(s); } else if(operate == "BACK") { backOperate(); } else { forwardOperate(); } } return 0; } void backOperate(void) { if(back.size()) { forward.push(current); current.assign(back.top()); back.pop(); cout<<current<<endl; return; } cout<<"Ignored"<<endl; } void forwardOperate() { if(forward.size()) { back.push(current); current.assign(forward.top()); forward.pop(); cout<<current<<endl; return; } cout<<"Ignored"<<endl; } void visitOperate(string s) { back.push(current); while(!forward.empty()) { forward.pop(); } current.assign(s); cout<<current<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator