标题:我有个网页导航题,代码写出来了,怎么也找不出错误,但上传就显示错误42%。 ...
取消只看楼主
nida_yede
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-3
结帖率:75%
已结贴  问题点数:10 回复次数:3 
我有个网页导航题,代码写出来了,怎么也找不出错误,但上传就显示错误42%。高手能帮我测试一下吗
下面是题还有代码:
题目:
Description
Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this.
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.


Input
Input is a sequence of commands. The command keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any time. The end of input is indicated by the QUIT command.


Output
For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print "Ignored". The output for each command should be printed on its own line. No output is produced for the QUIT command.


Sample Input
VISIT http://acm.ashland.edu/
VISIT http://acm.baylor.edu/acmicpc/
BACK
BACK
BACK
FORWARD
VISIT http://www.
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT

Sample Output
http://acm.ashland.edu/
http://acm.baylor.edu/acmicpc/
http://acm.ashland.edu/
http://www.
Ignored
http://acm.ashland.edu/
http://www.
http://acm.ashland.edu/
http://www.
http://acm.ashland.edu/
http://www.
Ignored


下面是代码:
#include <stdio.h>
#include <string.h>
int main()
{
    char CH3[120][10];
    int i,j,x=0,k=0,t,m=1,n=0,p=0;
    char CH1[120][70];
    for (i=0; i<120; i++)
       strcpy(CH1[i],"0");
    char CH2[4][10]= {"VISIT","BACK","FORWARD","QUIT"};
    strcpy(CH1[0],"http://www.);
   //freopen("in.txt","r",stdin);
    for (t=1;; t++)
    {
        scanf("%s",CH3[++k]);
        for (j=0; j<4; j++)
            if (strcmp(CH3[k],CH2[j])==0) break;
        if (j==0)
        {
            scanf("%s",CH1[++n]);
            printf("%s\n",CH1[n]);
            p=n;
            x=n;
        }
        else if (j==1)
        {
            if (strcmp(CH3[k-1],"VISIT")==0)
                {printf("%s\n",CH1[--p]);
                strcpy(CH1[++n],CH1[p]);}
            else if (strcmp(CH3[k-1],"BACK")==0)
            {
                if (p-1>=0)
                {
                    printf("%s\n",CH1[--p]);
                    strcpy(CH1[++n],CH1[p]);
                }
                else printf("Ignored\n");
            }
            else if (strcmp(CH3[k-1],"FORWARD")==0)
            {
                if (p-1<0||strcmp(CH1[p-1],"0")==0)
                    printf("Ignored\n");
                else
                {
                    printf("%s\n",CH1[--p]);
                    strcpy(CH1[++n],CH1[p]);
                }
            }
            else printf("Ignored\n");
        }
        else if (j==2)
        {
            if (strcmp(CH3[k-1],"VISIT")==0)
                printf("Ignored\n");
            else if (strcmp(CH3[k-1],"BACK")==0)
            {
                if (strcmp(CH1[p+1],"0")==0)
                    printf("Ignored\n");
                else
                {
                    printf("%s\n",CH1[++p]);
                    strcpy(CH1[++n],CH1[p]);
                }
            }
            else  if (strcmp(CH3[k-1],"FORWARD")==0)
            {
                if (strcmp(CH1[p+1],"0")==0||p+1>x)
                    printf("Ignored\n");
                else
                {
                    printf("%s\n",CH1[++p]);
                    strcpy(CH1[++n],CH1[p]);
                }
            }
            else printf("Ignored\n");
        }
        else break;
    }
}


求大神帮忙啊  速度!谢谢
搜索更多相关主题的帖子: 测试 导航 following recently backward 
2011-12-10 08:26
nida_yede
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-3
得分:0 
如果有人看到帖子的话,只要有兴趣就顶一下,我主动找阁下。然后看问题
谢了
2011-12-10 08:29
nida_yede
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-3
得分:0 
不是 ,我要你帮我找错误。
2011-12-10 08:52
nida_yede
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-3
得分:0 
  大哥,对照着题,帮我找下代码哪里错了?
2011-12-10 08:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-357432-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.134491 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved