PASCAL编程问题 ——Web浏览

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PASCAL编程问题 ——Web浏览相关的知识,希望对你有一定的参考价值。

题目描述

实现浏览器的页面前后访问机制。有四种命令:
1、BACK;
2、FORWARD;
3、VISIT:访问新的页面;
4、QUIT:退出浏览器。
请参考实际的浏览器按钮的功能。
假设浏览器打开时,显示的页面是:http://www.acm.org/
输入格式

一系列命令:以BACK、FORWARD、VISIT或QUIT开头。如果是VISIT,后面要跟URL,长度不超过70,且不含空格。最后总是以QUIT结尾。
输出格式

对于每一个命令(除了QUIT),输出浏览页面的URL,如果命令被忽略,输出:Ignored。

下面是我编的程序

type
stacks=record
data:array[0..1000000] of string;
top:0..1000000;
end;

var fullorder:string;
jilu:stacks;
a,k:longint;

procedure visit; ‘分别建立visit back forward三个过程
var wangzhi:string;
temp,kaitou:longint;

Begin
kaitou:=pos(' ',fullorder);
wangzhi:=copy(fullorder,kaitou+1,length(fullorder)-kaitou);
inc(a);
jilu.data[a]:=wangzhi;
writeln(jilu.data[a]);
jilu.top:=a;
end;

procedure back;
begin
dec(a);
If a<=0 then
BEGIN
inc(a);
writeln('Ignored');
end
else writeln(jilu.data[a]);
end;

procedure forwar;
begin
inc(a);
If a>jilu.top then
begin
dec(a);
writeln('Ignored');
end
else writeln(jilu.data[a]);
end;

Begin
jilu.top:=1;
jilu.data[jilu.top]:='http://www.acm.org/';
a:=jilu.top;

Repeat
readln(fullorder);
case fullorder[1] of
'V':visit;
'v':visit;
'F':forwar;
'f':forwar;
'B':back;
'b':back;
'Q':halt;
'q':halt;
end;
until false;
end.

可是测试结果只有90分

状态: Unaccepted
测评机: Xeost[5]
得分: 90分
提交日期: 2011-1-20 13:05:00
有效耗时: 1141毫秒
测试结果1: 通过本测试点|有效耗时156ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 运行错误|普通保护错误
测试结果5: 通过本测试点|有效耗时172ms
测试结果6: 通过本测试点|有效耗时172ms
测试结果7: 通过本测试点|有效耗时156ms
测试结果8: 通过本测试点|有效耗时63ms
测试结果9: 通过本测试点|有效耗时156ms
测试结果10: 通过本测试点|有效耗时172ms

请问我的程序还有哪个地方有问题吗?

你是做rqnoj的吧, 普通保护错误是内存限制或者边界问题,你仔细看看数组够不够大。
是不是要用ansistring.
这是我过了的程序,希望对你有帮助
var pre,next:array[1..100000]of longint;
a:array[1..100000]of string;
s,str:string;
l,now,tail:longint;
begin
a[1]:='http://www.acm.org/';
pre[1]:=0; now:=1; tail:=1;
readln(str);
while str<>'QUIT' do
begin
if str='BACK' then
begin
if pre[now]=0 then writeln('Ignored')
else begin now:=pre[now]; writeln(a[now]); end;
end
else if str='FORWARD' then
begin
if next[now]=0 then writeln('Ignored')
else begin now:=next[now]; writeln(a[now]); end;
end
else
begin
l:=length(str);
s:=copy(str,7,l-6);
inc(tail);
a[tail]:=s;
writeln(s);
next[now]:=tail;
pre[tail]:=now;
now:=tail;
end;
readln(str);
end;
end.
参考技术A var s:array[-1..1000]of string;
st:string;
i,t,k:longint;
begin
s[0]:='http://www.acm.org/';
while true do
begin
inc(k);
readln(st);
case st[1] of
'V':begin i:=k;
s[k]:=copy(st,7,length(st)-6); end;
'B':dec(k,2);
'Q':halt;
end;
if k=-1 then begin
writeln('Ignored');
k:=0;
end else
if k>i then begin
writeln('Ignored');
k:=i
end else writeln(s[k]);
end;
end.
LZ何苦这么累
参考技术B 你有数据吗?有的话麻烦发给我smaroc@163.com,谢谢。
首先设区间为[l,r]要求平均数>M。即我对于读入数据每个数减去M。然后求有多少种方案使得l到r的区间和大于0。对于样例:读入数据减去M得:0,4,-1,1。易知:有(2,2),(4,4),(1,2),(2,3),(1,3),(2,4),(1,4)7种情况使得区间和大于0。设a[i]表示第i个数减去M后的大小,sum[i]表示从a[1]累加到a[i]的和。要求区间[l,r]和大于0,即sum[r]-sum[l]>0其中(l<r)。然后这样就好办了。你既可以用归并排序求逆序对,也可以用平衡树来统计,还可以离散化后用树状数组……反正随便你怎么搞,总而言之nlogn出解。
这个程序是C++然后用的归并排序。
#include<iostream>
using namespace std;
const int maxn=100005;
int a[maxn]=,n,L,sum[maxn]=,temp[maxn];
long long ans=0;

void Init()

int x,i;
cin>>n>>L;
sum[0]=0;a[0]=0;
for(i=1;i<=n;i++)

void Dichotomize(int l,int r)

if(l==r)return;
int mid=(l+r)/2;
Dichotomize(l,mid);
Dichotomize(mid+1,r);
int p1=l,p2=mid+1,p3=l,i;
while( p1<=mid&&p2<=r)
if( a[p1]>a[p2])

ans+=mid-p1+1;
temp[p3++]=a[p2++];

else temp[p3++]=a[p1++];
while( p1<=mid)temp[p3++]=a[p1++];
while( p2<=r)temp[p3++]=a[p2++];
for( i=l;i<=r;i++)a[i]=temp[i];

int main()

Init();
Dichotomize(0,n);
cout<<ans;
return 0;

一天一门编程语言Pascal 语言程序设计极简教程

Pascal 语言程序设计极简教程

用 markdown 格式输出答案。 不少于3000字。细分到2级目录。

文章目录

以上是关于PASCAL编程问题 ——Web浏览的主要内容,如果未能解决你的问题,请参考以下文章

一天一门编程语言Pascal 语言程序设计极简教程

如何以编程方式监控 Web 浏览器中的 JavaScript 执行?

pascal编程exitcode=201错误

Pascal之父编程祖师爷尼古拉斯•威茨痛批:教授成了项目经理,大学过于“重论文轻教学“...

零基础想入门编程需要先学啥

在 Python 中以编程方式在 Web 浏览器中打开 URL