Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 29450 | Accepted: 13160 |
Description
The following commands need to be supported:
BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.
FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.
VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
QUIT: Quit the browser.
Assume that the browser initially loads the web page at the URL http://www.acm.org/
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
Source
East Central North America 2001
雖然是水題,,但是。。wa幾次。。哭死。。沒注意一句話
VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page.
The forward stack is emptied.
要把後面的去掉
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
string left,right;
vector<string> all(105);
int k,r;
k=r=0;
all[k++]="http://www.acm.org/";
while(cin>>left){
if(left=="VISIT"){
cin>>right;
all[k++]=right;
cout<<right<<endl;
for(int i=k;i<all.size();i++)
all[i]="";
}else if(left=="BACK"){
k--;
if((k-1)<0) {
cout<<"Ignored"<<endl;
k=1;
}else{
right=all[k-1];
cout<<right<<endl;
}
}else if(left=="FORWARD"){
k++;
right=all[k-1];
if(right.size()<=0){
cout<<"Ignored"<<endl;
k--;
}else
cout<<right<<endl;
}else{
if(left=="QUIT") break;
}
}
return 0;
}