1989年计算机应用软件人员水平考试——下午试题

发表于:2007-05-26来源:作者:点击数: 标签:
试题一 [说明] 流程图1.1实现了一个将一组无序数列a1,a2,...,an排成递增序列的算法. 该算法在s-1到r(初值为1到n)的区间内,先冒泡后进行排序,直到该区间为空.图 中变量K用来指出一次冒泡或下沉后a1--ak或ak--an已排序. 试题3 阅读下列程序说明和PASCAL程序,把
试题一

[说明]

流程图1.1实现了一个将一组无序数列a1,a2,...,an排成递增序列的算法.

该算法在s-1到r(初值为1到n)的区间内,先冒泡后进行排序,直到该区间为空.图

中变量K用来指出一次冒泡或下沉后a1--ak或ak--an已排序.


试题3

阅读下列程序说明和PASCAL程序,把应填入其中_______处的字句,写在答卷的

对应栏内.

[程序说明]

本题给出的子程序用来寻找第一个均出现在三个整数链表中的相同整数.假定

在调用该子程序前,这三个整数链表已按从小到大的次序排序.有关的类型定义如下:

type pt=^elem;

elem=record

int:integer;

link:pt

end;

[程序]

procedure lookint (f1,f2,f3:pt; var found:boolean; var val:integer);

var exit:boolean;

begin found:=false;


while ____________ and not found do

begin


if __________________

then f1:=f1^.link


else if _______________

then f2:=f2^.link

else found:=true;

if found

then begin found:=false; exit:=true;

while (f3<>nil) and not found and exit do

if f3^.int=f1^.int

then found:=true


else if ___________________

then f3:=f3^.link


else begin _______________;

exit:=false

end

end

end;

if found then val:=f1^.int

end;


试题7

[程序说明]

本子程序用来建立一个已知文件的索引文件.建立索引的关键字段名为key.

设有类型:

seqelement=record ..., key:simpletype, ... end;

tmpelement=record {工作文件的成分类型}

key : simpletype; {存贮关键字值}

no : integer {对应的已知文件成分的序号}

end;

tseqfile = file of seqelement; {已知文件的类型}

tindxfile = file of integer; {索引文件类型}

其中 simpletype 是某简单顺序类型名.

为建立索引文件,子程序引入一个数组a与两个工作文件g,h.

建立索引文件的方法是:

首先重复执行以下步骤,直至已知文件读完:

1. 从已知文件读出多至100个记录,将记录中关键项的值及该记录的序号

送到数组a;

2. 对a按关键字值从小到大排序;

3. 将a与文件g(或h)合并于文件h(或g).合并时,使文件h(或g)是按关键字

值排序的.

然后由文件h(或g)生成索引文件.


[程序]

procedure indexed (var seqfile : tseqfile; var index file : tindxfile);

const arsize = 100;

type tmparray = array [1..arsize] of tmpelement;

tmpfile = file of tmpelement;

var a : tmparray;

g,h : tmpfile;

n,recno : integer;

s : boolean;

procedure sort(var a : tmparray; n : integer); {将数组a的前n个元素

按key递增排序,本过程的过程体省略}

procedure combi(var f1,f2 : tmpfile); {将文件f1与数组a按关键字值从

小到大合并于文件f2}

var i,j : integer;

begin i:=1; reset(f1); rewrite(f2);

while ________________ do

begin

if f1^.key <= a.key then

begin f2^:=f1^; get(f1) end

else

begin ___________ ; __________ end;

put (f2);

end;

while not eof(f1) do

begin f2^:=f1^; get(f1); put(f2) end;

for j:= i to n do

begin f2^:=a[j]; put(f2) end

end;

procedure gindex (var f:tmpfile);

begin rewrite (indexfile); reset(f);

while not eof(f) do

begin indexfile^:=f^.no;

put (indexfile); get(f)

end

end;

begin reset(seqfile); recno:=0;s:=true;

repeat n:=0 ;

while ____________ do

begin n:=n+1; a[n].key:=seqfile^.key;

recno:=recno+1;a[n].no:=recno;

get(seqfile)

end;

sort(a,n);

if s then combi(g,h)

else combi(h,g);

_______________________

until eof (seqfile);

if ________________ then gindex(g)

else gindex(h)

end;


试题11

[程序说明]

本程序能从1至n(n<1000)的自然数中取r个数的所有组合,并按指定的格

式输出其结果.例如,n=5,r=3时,共有10种组合(见下面左边列表),而程序将按

下面右边列表形式输出(每一行前有一空格).

10种组合 程序输出形式

combinations:

1,2,3 1 2 3

1,2,4 4

1,2,5 5

1,3,4 3 4

1,3,5 5

1,4,5 4 5

2,3,4 2 3 4

2,3,5 5

2,4,5 4 5

3,4,5 3 4 5

[程序]

program comnr(input,output);

var n,r:integer;

blank:boolean;

proecdure combination(s,j:integer);

var i:integer;

begin

for i:= _____________ to n-j+1 do

begin

if ____________ then write (' ':______________*3+1);

write (i:3); blank:=false;

if ___________________ then

combination (______________)

else begin

writeln;

______________________

end

end

end;

begin writeln('ENTER N,R.');

readln(n,r); blank:=true;

writeln('combinations:');

combination(1,r)

end.

原文转自:http://www.ltesting.net