Informatika gyűjtemény

Egy szinttel feljebb pr_selejtezo.pas

2004050607080910

NézetNyomtat

pr_selejtezo.pas (Vissza)
Az alábbi letöltési lehetőségek közül választhatsz: (segítség)
Karakterkódolás:
Sortörés:
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 687 byte
program ford;

var a:array[1..100] of longint;
t1,t2:text;
i,j,c,p:longint;
cass,cdb,lof,ma:longint;

begin
assign(t1,'ford.be'); reset(t1);
readln(t1,cdb);
assign(t2,'ford.ki'); rewrite(t2);

for cass:=1 to cdb do begin

read(t1,p); read(t1,c);
for i:=1 to p do read(t1,a[i]); a[p+1]:=1; lof:=0;

for i:=1 to p-1 do begin for j:=i+1 to p do begin
if a[j]>a[i] then begin
ma:=a[i]; a[i]:=a[j]; a[j]:=ma;
end; end; end;

while a[c]>0 do begin


for i:=1 to c do a[i]:=a[i]-1;
lof:=lof+1;

for i:=1 to p-1 do begin for j:=i+1 to p do begin
if a[j]>a[i] then begin
ma:=a[i]; a[i]:=a[j]; a[j]:=ma;
end; end; end;

end;

writeln(t2,'Case #',cass,': ',lof);

end;
close(t1);
close(t2);


end.
(Vissza)