pascal 完善程序题

来源:百度知道 编辑:UC知道 时间:2024/05/08 04:29:29
各位大哥大姐帮帮忙吧~~~
1.连续整数平台问题
已知一个含有多个整数的数组,其中相同的元素集中在一起形成一个平台。以下程序用于对输入的数组求出其中最大平台长度。例如,中元素个数为20,它们依次为
2 2 2 2 3 3 3 3 3 1 1 1 1 1 1 1 1 1 4 4
则它的最大平台长度为9(9个1~~)
program
const maxlength=100;
var
a:array<1..maxlength> of integer;
i,maxi,n,s,t:integer;
begin
write('n=');readln(n);
for i:=1 to n do read(a<i>);
readln;
maxi:=o;
t:=第一个空
s:=1;
for i:=2 to n do
if a<i>=t then 第二个空
else
begin
if s>maxi then maxi:=s;
t:=a<i>;
第三个空
end;
第四个空
writeln('maxi=',maxi);
end.

第1个空:a[1];
第2个空: s:=0;
第3个空: inc(s);
第4个空: if s>maxi then maxi:=s

program
const maxlength=100;
var
a:array<1..maxlength> of integer;
i,maxi,n,s,t:integer;
begin
write('n=');readln(n);
for i:=1 to n do read(a<i>);
readln;
maxi:=o;
t:=a[1];
s:=1;
for i:=2 to n do
if a<i>=t then s:=0;
else
begin
if s>maxi then maxi:=s;
t:=a<i>;
inc(s);
end;
inc(s);
writeln('maxi=',maxi);
end.

第1个空:a[1];
第2个空: s:=0;
第3个空: inc(s);
第4个空: if s>maxi then maxi:=s