Web Navigation
Description
The following commands need to be supported:
BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.
FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.
VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
QUIT: Quit the browser.
Assume that the browser initially loads the web page at the URL http://www.acm.org/
Input
Output
Sample Input
VISIT http://acm.ashland.edu/ VISIT http://acm.baylor.edu/acmicpc/ BACK BACK BACK FORWARD VISIT http://www.ibm.com/ BACK BACK FORWARD FORWARD FORWARD QUIT
Sample Output
http://acm.ashland.edu/ http://acm.baylor.edu/acmicpc/ http://acm.ashland.edu/ http://www.acm.org/ Ignored http://acm.ashland.edu/ http://www.ibm.com/ http://acm.ashland.edu/ http://www.acm.org/ http://acm.ashland.edu/ http://www.ibm.com/ Ignored
1 Source Code 2 3 Problem: 1028 User: 13408100238 4 Memory: 200K Time: 0MS 5 Language: C++ Result: Accepted 6 Source Code 7 #include"iostream" 8 #include"cstring" 9 #include"string" 10 #include"stack" 11 using namespace std; 12 int main() 13 { 14 stack<string> s1,s2; 15 string s,ss; 16 s="http://www.acm.org/"; 17 s1.push(s); 18 while(cin>>s) 19 { 20 if(s=="QUIT") 21 break; 22 if(s=="VISIT") 23 { 24 cin>>ss; 25 cout<<ss<<endl; 26 s1.push(ss); 27 while(!s2.empty()) 28 s2.pop(); 29 } 30 else if(s=="BACK") 31 { 32 //cout<<"back "<<s1.size()<<endl; 33 if(s1.size()>=2) 34 { 35 s2.push(s1.top()); 36 s1.pop(); 37 cout<<s1.top()<<endl; 38 } 39 else 40 cout<<"Ignored"<<endl; 41 } 42 else if(s=="FORWARD") 43 { 44 if(!s2.empty()) 45 { 46 cout<<s2.top()<<endl; 47 s1.push(s2.top()); 48 s2.pop(); 49 } 50 else 51 cout<<"Ignored"<<endl; 52 } 53 } 54 return 0; 55 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。