Jump pages (multiple stacks)

 

 

 

 

Topics requirements:

Jun garlic in software with a product called "garlic plant Browser" every day. In the browser, a total of three operations: Open the page, rewind and forward. Their functions are as follows:

Open the page: enter the URL in the address bar, and jump to the corresponding page URL;

  • Fallback: Return to the previous page visit;
  • Forward: Returns to the page before the last fallback if the previous operation was to open the page, it will not move forward.
  • Now, garlic Jun open the browser, a series of operations, you need to output after each operation where he URLs page.

Input Format

A first line of input integer n (0 <n \ le 100000) n (0 <n≤100000), represents the number of operation garlic Jun.

Next, a total of nn lines of a first input string, if the VISIT, followed by entering a URL does not contain a space and a line feed (URL length is less than 100,100), the URL entered represents Jun garlic browser address bar; if It is bACK, represents the garlic king clicked the back button; if it is fORWARD, represents the garlic king clicking the forward button.

Output Format

For each operation, if the garlic king can operate after a successful web site, garlic king output, otherwise the output Ignore. Assuming that all URLs garlic king entered are legitimate.

Sample input

10
VISIT https://www.jisuanke.com/course/476
VISIT https://www.taobao.com/
BACK
BACK
FORWARD
FORWARD
BACK
VISIT https://www.jisuanke.com/course/429
FORWARD
BACK

Sample Output

https://www.jisuanke.com/course/476
https://www.taobao.com/
https://www.jisuanke.com/course/476
Ignore
https://www.taobao.com/
Ignore
https://www.jisuanke.com/course/476
https://www.jisuanke.com/course/429
Ignore
https://www.jisuanke.com/course/476

 

 

Ideas: https://blog.csdn.net/weixin_44336954/article/details/92025250

 

Code from: https://blog.csdn.net/biubiupa233/article/details/79521058

. 1 #include <the iostream>
 2 #include <Stack>
 . 3 #include < String >
 . 4  the using  namespace STD;
 . 5  int main () {
 . 6      iOS :: sync_with_stdio ( 0 ); // to avoid input and output timeout 
. 7      Stack < String > S1 ; // store backward site 
. 8      Stack < String > S2; // store site forward 
. 9      int n-;
 10      CIN >> n-;
 . 11      the while (N-- ) {
 12 is          Stringstr1, str2;
 13          cin >> str1;
 14          IF (str1 == " VISIT " ) { 
 15              cin >> str2;
 16              the while (! s2.empty ()) // If there is access to the site empty forward 
17                  s2. POP ();
 18              s1.push (str2); // back into the store site is currently visiting the site,
 19                            // and so the time to retreat into this site can be extracted site in advance to 
20              cout << s1. Top () << endl;
 21 is          }
 22 is          the else  IF (str1 == " the BACK " ) {
23              IF (s1.empty ()) cout << " Ignore " << endl; // If you want to back site of the stack is empty 
24-              the else { // not empty 
25                  s2.push (s1.top ()); // the stack before the site visit, deposit forward website in 
26                  s1.pop ();
 27                  IF (! s1.empty ()) cout << s1.top () << endl; // retreat site the stack is not empty then the output 
28                  the else { // empty 
29                      s1.push (s2.top ()); // store a state before the return 
30                      s2.pop ();
 31 is                      COUT << "Ignore" << endl;
32                 }
33             }
34         }
35         else {
36             if (s2.empty())//前进为空 
37                 cout << "Ignore" << endl;
38             else {//不为空 
39                 cout << s2.top() << endl;
40                 s1.push(s2.top());
41                 s2.pop();    
42             }
43         }
44     }
45     return 0;
46 }

Guess you like

Origin www.cnblogs.com/jiamian/p/12164579.html