标签:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 30689 | Accepted: 13750 |
Description
Input
Output
Sample Input
VISIT http://acm.ashland.edu/ VISIT http://acm.baylor.edu/acmicpc/ BACK BACK BACK FORWARD VISIT http://www.ibm.com/ BACK BACK FORWARD FORWARD FORWARD QUIT
Sample Output
http://acm.ashland.edu/ http://acm.baylor.edu/acmicpc/ http://acm.ashland.edu/ http://www.acm.org/ Ignored http://acm.ashland.edu/ http://www.ibm.com/ http://acm.ashland.edu/ http://www.acm.org/ http://acm.ashland.edu/ http://www.ibm.com/ Ignored
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#define N 109
using namespace std;
char a[N];
string s="http://www.acm.org/";
int main()
{
stack<string>bac,fwd;
while(~scanf("%s",a))
{
if(a[0]=='Q') break;
if(a[0]=='V')
{
bac.push(s);
cin>>s;
cout<<s<<endl;
while(!fwd.empty()) fwd.pop();
}
else if(a[0]=='B')
{
if(!bac.empty())
{
fwd.push(s);
s=bac.top();
bac.pop();
cout<<s<<endl;
}
else cout<<"Ignored"<<endl;
}
else if(a[0]=='F')
{
if(!fwd.empty())
{
bac.push(s);
s=fwd.top();
fwd.pop();
cout<<s<<endl;
}
else cout<<"Ignored"<<endl;
}
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/wust_zjx/article/details/45648053