ny_666 2023-05-28 10:18 采纳率: 50%
浏览 23
已结题

关于#解答#的问题,如何解决?

img

img


请解答一下
谢谢
(麻烦把代码发在评论区,谢谢)

oi.nks.edu.cn

px.lboj.com.cn

  • 写回答

1条回答 默认 最新

  • threenewbee 2023-05-28 10:36
    关注
    #include <iostream>  
    #include <stack>
    #include<string>
    
    using namespace std;
    
    int main()  
    {
        stack<string> st1, st2;  
        string cmd;
    
        while (true)  
        {  
            getline(cin, cmd);
    
            if (cmd == "QUIT")  
            {  
                break;  
            }
    
            if (cmd.substr(0, 4) == "VISI" && cmd.substr(0, 6) == "VISIT ")  
            {  
                st1.push(cmd.substr(6));  
                cout << st1.top() << endl;  
            }
    
            else if (cmd == "BACK")  
            {  
                if (st1.empty())  
                {  
                    cout << "Ignored" << endl;  
                }  
                else  
                {  
                    st2.push(st1.top());  
                    st1.pop();
                    cout << st2.top() << endl;  
                }  
            }
    
            else if (cmd == "FORWARD")  
            {  
                if (st2.empty())  
                {  
                    cout << "Ignored" << endl;  
                }  
                else  
                {  
                    st2.push(st2.top());
                    st2.pop();
                    cout << st1.top() << endl;  
                }  
            }  
        }
    
        return 0;  
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 6月5日
  • 已采纳回答 5月28日
  • 创建了问题 5月28日

悬赏问题

  • ¥50 求恶意流量检测系统搭建教程( C++ python C)
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys