请问这道Pascal程序题应该如何解答

请问这道Pascal程序题应该如何解答,第1张

输出结果是 98 303 100

因为a是值参,传递后仍是原值;第2个形参x是变参,传递给过程中的y(与主程序中的y无关)后在过程中减了25,变成98。

所以三变量的输出就是 98 303 100

先做一个

题三

Program succor;

var a,b:array[1100] of longint;

m,i,j:integer;

t,n:longint;

f:boolean;

fg,eg:text;

Begin

assign(fg,'succorin');

reset(fg);

assign(eg,'succorout');

rewrite(eg);

readln(m);

read(fg,a[1]); b[1]:=1;

i:=1;

repeat

i:=i+1;

b[i]:=0; f:=true;

read(fg,n);

for j:=1 to i-1 do

if n=a[j] then begin b[j]:=b[j]+1; f:=false; end;

if f then begin a[i]:=n; b[i]:=b[i]+1; end;

until i=m;

for i:=1 to m-1 do

for j:=i+1 to m do begin

if b[i]<b[j] then begin

t:=a[i]; a[i]:=a[j]; a[j]:=t;

t:=b[i]; b[i]:=b[j]; b[j]:=t; end;

if b[i]=b[j] then

if a[i]>a[j] then

begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end;

end;

write(eg,a[1]);

for i:=2 to m do if a[i]<>0 then

write(eg,'->',a[i]);

close(fg);

close(eg);

Writeln('Press [Enter] to continue ');

Readln;

End

先使用快速排序对漂亮值由大到小排序,然后在s值中寻找最长上升子序列。对于本题来说,是最长不下降子序列,而且要注意漂亮值相等时要特殊处理。

var

b,s,v:array[0100000] of longint;

n,i,j,k,max,ans:longint;

procedure qsort(l,r:longint);

var i,j,t,x:longint;

begin

i:=l; j:=r; x:=(i+j) div 2;

repeat

while b[i]>b[x] do inc(i);

while b[j]<b[x] do dec(j);

if j>=i then

begin

t:=b[i];

b[i]:=b[j];

b[j]:=t;

t:=s[i];

s[i]:=s[j];

s[j]:=t;

inc(i);

dec(j);

end;

until i>j;

if l<j then qsort(l,j);

if i<r then qsort(i,r);

end;

procedure sort(l,r:longint);

var i,j,t:longint;

begin

for i:=r-1 downto l do

for j:=l to i do

if s[j]>s[j+1] then

begin

t:=s[j];

s[j]:=s[j+1];

s[j+1]:=t;

end;

end;

begin

readln(n);

for i:=1 to n do readln(s[i],b[i]);

qsort(1,n);

i:=0;

repeat

inc(i);

if b[i+1]=b[i] then

begin

k:=i;

while (b[k]=b[k+1])and(k<=n) do inc(k);

sort(i,k);

i:=k;

end;

until i>n;

ans:=-maxlongint;

for i:=1 to n do

begin

max:=-maxlongint;

for j:=i downto 0 do if (s[i]>=s[j]) and ((v[j]+1)>max) then max:=v[j]+1;

v[i]:=max;

if max>ans then ans:=max;

end;

writeln(ans);

end

一、单项选择题:(每题15分)

1 D 2 D 3 C 4 B 5 B 6B 7 B 8 C

9 C 10 A

11 C 12 A 13 A 14 A 15 B 16 D 17 C 18 D

19 A 20 A

二、问题求解:(每题 5分)

1.90

2.210

三、阅读程序写结果

1 15, 46(对1个数给4分,无逗号扣1分)

2 3, 6

3 2 3 5 7 11 13 17 19 23 29

31 37 41 43 47

4 wer2345defgh45456782qqq

四、完善程序(前4空(①--④),每空25分,后6空(⑤--⑩),每空3分)

(说明:以下各程序填空可能还有一些等价的写法,各省可请本省专家审定和上机验证,不一定上报科学委员会审查)

1.① inc(i) 或i:=i+1

② dec(j) 或 j:=j-1

③ kz<>-1

④ reverse(line)

2 ⑤ exit

⑥ (dr<tr+s)and(dc<tc+s)

⑦ chessboard(tr,tc,tr+s-1,tc+s-1,s)

⑧ chessboard(tr,tc+s,tr+s-1,tc+s,s)

⑨ chessboard(tr+s,tc,tr+s,tc+s-1,s)

⑩ chessboard(tr+s,tc+s,tr+s,tc+s,s)

以上就是关于请问这道Pascal程序题应该如何解答全部的内容,包括:请问这道Pascal程序题应该如何解答、pascal语言简单的题目(我要完整的程序)、请教一道pascal程序题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10106703.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存