1028 12th

模拟没超时- -

Code:
  1. //============================================================================   
  2. // Name        : 1028.cpp   
  3. // Author      : kevin   
  4. // Version     :   
  5. // Copyright   : copyright @ kevin   
  6. // Description : Hello World in C++, Ansi-style   
  7. //============================================================================   
  8.   
  9. #include <iostream>   
  10. #include<stack>   
  11. #include<string>   
  12. using namespace std;   
  13. int main() {   
  14.     stack<string> forwardStack;   
  15.     stack<string> backStack;   
  16.     string currentPage="http://www.acm.org/";   
  17.     const int MAX=100;   
  18.     char str[MAX];   
  19.     char op[10];   
  20.     cin>>op;   
  21.     while(op[0]!='Q'){   
  22.         if(op[0]=='V'){   
  23.             cin>>str;   
  24.             cout<<str<<endl;   
  25.             backStack.push(currentPage);   
  26.             while(!forwardStack.empty())   
  27.                 forwardStack.pop();   
  28.             currentPage=str;   
  29.         }   
  30.         if(op[0]=='B'){   
  31.   
  32.             if(!backStack.empty()){   
  33.                 forwardStack.push(currentPage);   
  34.                 currentPage=backStack.top();   
  35.                 backStack.pop();   
  36.                 cout<<currentPage<<endl;   
  37.             }else  
  38.                 cout<<"Ignored"<<endl;   
  39.         }   
  40.         if(op[0]=='F'){   
  41.   
  42.             if(!forwardStack.empty()){   
  43.                 backStack.push(currentPage);   
  44.                 currentPage=forwardStack.top();   
  45.                 forwardStack.pop();   
  46.                 cout<<currentPage<<endl;   
  47.             }else  
  48.                 cout<<"Ignored"<<endl;   
  49.         }   
  50.         cin>>op;   
  51.     }   
  52.     return 0;   
  53. }   

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值