| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 793 人关注过本帖
标题:我有个网页导航题,代码写出来了,怎么也找不出错误,但上传就显示错误42%。 ...
只看楼主 加入收藏
nida_yede
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-12-3
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:6 
我有个网页导航题,代码写出来了,怎么也找不出错误,但上传就显示错误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
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:3 
无论是VC的HTMLview 还是IE Active 都带了这个功能
貌似IE内核本身就做好了,所以咋不考虑这个题。
还有 STL 和 string 处理这类问题很强大的!
2011-12-10 08:48
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
jfei
Rank: 4
来 自:郑州
等 级:业余侠客
帖 子:92
专家分:268
注 册:2011-8-27
收藏
得分:3 
#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;/*循环变量i,j*/
    char CH1[120][70];
    for (i=0; i<120; i++)
       strcpy(CH1[i],"0");/*ch1[120][70]赋初值'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]);/*ch3[120][0]为null,因为是++k,改成k++*/
        for (j=0; j<4; j++)
            if (strcmp(CH3[k],CH2[j])==0) break;/*如果输入的是vist,back,forward,quit,退出内循环,进入外循环*/
        if (j==0)/*木有执行strcmp(ch2[k],ch2[j])==0,对ch1,进行赋值*/(1)
        {
            scanf("%s",CH1[++n]);
            printf("%s\n",CH1[n]);/**输出内容 %s 以啥符号结尾呢,**/
            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;(4)
    }
}
/**另外也没有显示出菜单按钮,外循环没有跳出来(4)不可能执行,执行(1)的情况多一些,用到的函数strcpy()和strcmp(),通过strcpy()完成上传功能,效率受影响,自我赋值,交换数组下标,其它啥也木有**/

虾米们!!!有意者加QQ 2434202652,2632939128联系我
2011-12-10 11:27
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
收藏
得分:3 
程序代码:
#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];
    char CH2[4][10]={"VISIT","BACK","FORWARD","QUIT"};

    for (i=0; i<120; i++)
       strcpy(CH1[i],"0");
    
    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;
    }
}
貌似我还没见过 在c中定义数据类型用c++语法的  程序正误我没改 只是调整下了定义数据类型时的顺序 使程序编译通过了
2011-12-11 10:35
快速回复:我有个网页导航题,代码写出来了,怎么也找不出错误,但上传就显示错误 ...
数据加载中...
 
   



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

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