Zbiór
Deklaracja:
Działania na zbiorach
type T = set of T0;
var A,B,C : T;
x:boolean;
begin
............................
C := A + B;
C := A * B;
C := A – B;
x := A = B; //równość zbiorów
x := A <> B; //not (A=B)
x := A <= B; //A jest podzbiorem B
x := A >=B; //B jest podzbiorem A
x := y in A; //czy y zawiera się w A
end.
Wyświetlanie najmniejszego elementu ze zbioru
const N = 100;
var
x : 1..N;
A : set of 1..N;
begin
A := [10,16,12,3,8];
x :=1;
while not (x in A) do x := succ(x);
writeln(x);
end.
Zliczanie elementów w zbiorze
Const N = 100;
var
A,A1 : set of 1..N;
i : byte;
x : 1..N;
begin
A := [1,2,6,10];
i := 0;
if A <> [] then begin
x := 1;
A1 := A;
repeat
while not(x in A1) do x := succ(x);
inc(i);
A1 := A1-[x];
until A1 = [];
end;
writeln(i);
end.
Wyświetlanie zawartości zbioru
Const N = 100;
var
A,A1 : set of 1..N;
i : byte;
x : 1..N;
begin
A := [1,2,6,10];
i := 0;
if A <> [] then begin
x := 1;
A1 := A;
repeat
while not(x in A1) do x := succ(x);
inc(i);
writeln(x); //wyswietlenie na ekran
A1 := A1-[x];
until A1 = [];
end;
writeln(i);
end.
Podobne strony
Podobne Strony • Inline • Obsługi warunków i stanów wyjątkowych • Destruktor • Konstruktor • Of • Asm • Typ obiektowy • Struktura modułu • Label • Pętla Repeat Until • Instrukcja "jeśli" • Instrukcja wiążąca • Goto • Funkcja • End • Instrukcje warunkowe • Typ tablicowy • Instrukcja wyboru • Typ Rekordowy • Typ Plikowy
wersja strony: 8, ostatnia edycja: 16 Jul 2009 12:07