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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MaxSize 100
typedef struct
{
int Top;
int pre;
}Stack;
int main()
{ char Data[MaxSize][103];
char str[101];
char wb[101]="http://www.acm.org/";
Stack S;
Stack *Ptrs;
Ptrs=&S;
Ptrs->pre=Ptrs->Top=0;
strcpy(Data[0],wb);
while(scanf("%s",str)!=EOF)
{
if(strcmp(str,"QUIT")==0)
break;
if(str[0]=='V')
{
scanf("%s",wb);
strcpy(Data[(++Ptrs->pre)],wb);
Ptrs->Top=Ptrs->pre;
printf("%s\n",wb);
}
else if(str[0]=='B')
{
if(Ptrs->pre>0)
{
Ptrs->pre--;
printf("%s\n",Data[Ptrs->pre]);
}
else
printf("Ignored\n");
}
else if(str[0]=='F')
{
if(Ptrs->pre<Ptrs->Top)
{
Ptrs->pre++;
printf("%s\n",Data[Ptrs->pre]);
}
else
printf("Ignored\n");
}
getchar();
}
return 0;
}