zoj-1061

来源:互联网 发布:影视制作的软件 编辑:程序博客网 时间:2024/04/29 17:39

挺喜欢这题的,代码是别人的,写的很规范。

#include<iostream>#include<stack>#include<fstream>#include<cstring>using namespace std;void ClearStack(stack<string>&s){    while(!s.empty())        s.pop();}int main(){    //fstream cin("d:\\test.txt");    string command,newUrl;    int n,cnt;    cin>>n;    for(cnt=1;cnt<=n;++cnt)    {        stack<string> forwardStack,backwardStack;        string curUrl="http://www.acm.org/";        if(cnt!=1)            cout<<endl;        while(cin>>command)        {            if(command[0]=='Q')                break;            else if(command[0]=='B')            {                if(!backwardStack.empty())                {                    forwardStack.push(curUrl);                    curUrl=backwardStack.top();                    cout<<curUrl<<endl;                    backwardStack.pop();                }                else                    cout<<"Ignored"<<endl;            }            else if(command[0]=='V')            {                backwardStack.push(curUrl);                cin>>curUrl;                cout<<curUrl<<endl;                ClearStack(forwardStack);            }            else if(command[0]=='F')            {                if(!forwardStack.empty())                {                    backwardStack.push(curUrl);                    curUrl=forwardStack.top();                    cout<<curUrl<<endl;                    forwardStack.pop();                }                else                    cout<<"Ignored"<<endl;            }        }    }    return 0;}