计蒜客--网页跳转问题

 

AC代码:

#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
    ios::sync_with_stdio(false);   //避免超时
    stack<string> s1;
    stack<string> s2;
    int n;
    cin >> n;
    while (n--) {
        string str1, str2;
        cin >> str1;
        if (str1 == "VISIT") {
            cin >> str2;
            while (!s2.empty()) {//清空s2
                s2.pop();
            }
            s1.push(str2);
            cout << s1.top() << endl;
        }
        else if (str1 == "BACK") {
            if (s1.empty()) {
                cout << "Ignore" << endl;
            }
            else {
                s2.push(s1.top());
                s1.pop();
                if (!s1.empty()) {
                    cout << s1.top() << endl;
                }
                else {
                    cout << "Ignore" << endl;
                    s1.push(s2.top());
                    s2.pop();
                }
            }
        }
        else {
            if (s2.empty()) {
                cout << "Ignore" << endl;
            }
            else {
                if (!s2.empty()) {
                    cout << s2.top() << endl;
                    s1.push(s2.top());
                    s2.pop();
                }
                else {
                    cout << "Ignore" << endl;
                }
            }

        }
    }
}
原文地址:https://www.cnblogs.com/pythonbigdata/p/8748125.html