Web Navigation(浏览器浏览网页模拟)

问题:
浏览器浏览网页模拟。

VISIT:访问。
BACK:后退。
FORWARD:前进。
QUIT:退出。

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 
#include
#include
#include 
#define maxn 100000
using namespace std;
typedef struct
{
    char a[maxn];
    int top;
} SqStack;
void InitStack(SqStack *&l1)
{
    l1=(SqStack*)malloc(sizeof(SqStack));
    l1->top=0;
}
void StackPush(SqStack*&ps, char x)
{
    ps->a[ps->top] = x;
    ps->top++;
}
void StackPop(SqStack*&ps)
{
    --ps->top;
}
char StackTop(SqStack*&ps)
{
    return ps->a[ps->top - 1];
}
int main()
{
    SqStack *l,*s;
    InitStack(l);
    InitStack(s);
    StackPush(l,'0');                        //初始字符为'0',("http://www.acm.org/")。
    string str;
    while(cin>>str)
    {
        char st;
        if(str.compare("QUIT")==0)
            break;
        else if(str.compare("VISIT")==0)
        {
            cin>>st;
            StackPush(l,st);
            cout<top!=0)
                StackPop(s);
        }
        else if(str.compare("BACK")==0)
        {
            if(l->top>0)
            {
                StackPush(s,StackTop(l));
                StackPop(l);
                cout<top>0)
            {
                StackPush(l,StackTop(s));
                cout<

二、代码实现

这个代码 可以输入字符串(网址)。

#include
#include
#include
#include
using namespace std;

int main()
{
    stack back,forward;
    string now,URL;
    back.push("http://www.acm.org/");
    while(cin>>now)
    {
        if(now.compare("QUIT")==0)
            break;
        else if(now.compare("VISIT")==0)
        {
            cin>>URL;
            back.push(URL);
            cout<1)
            {
                forward.push(back.top());
                back.pop();
                cout<

你可能感兴趣的:(暑假集训)