站外求助
查看原帖
站外求助
664234
I_AM_THREE_BODY_MAN楼主2024/7/15 16:23

题目传送门

自己写了一个代码,超时两个点,求帮助

#include<bits/stdc++.h>
using namespace std;
stack<string> forw,back;
string x,url;
int main(){
    back.push("https://keda.ac/");
    while(1){
        cin>>x;
        if(x == "VISIT"){
            cin>>url;
            back.push(url);
            while(!forw.empty()) forw.pop();
            cout<<back.top()<<endl;
        }
        else if(x=="BACK"){
            if(back.size()<=1) cout<<"Ignored"<<endl;
            else{
                forw.push(back.top());
                back.pop();
                cout<<back.top()<<endl;
            }
        }
        else if(x=="FORWARD"){
            if(forw.empty()) cout<<"Ignored"<<endl;
            else{
                back.push(forw.top());
                forw.pop();
                cout<<back.top()<<endl;
            }
        }
        else break;
    }
    return 0;
}
2024/7/15 16:23
加载中...