Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
83
Task/Set-consolidation/Draco/set-consolidation.draco
Normal file
83
Task/Set-consolidation/Draco/set-consolidation.draco
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
type Set = word;
|
||||
|
||||
proc make_set(*char setdsc) Set:
|
||||
Set set;
|
||||
byte pos;
|
||||
set := 0;
|
||||
while setdsc* /= '\e' do
|
||||
pos := setdsc* - 'A';
|
||||
if pos < 16 then set := set | (1 << pos) fi;
|
||||
setdsc := setdsc + 1
|
||||
od;
|
||||
set
|
||||
corp
|
||||
|
||||
proc write_set(Set set) void:
|
||||
char item;
|
||||
write('(');
|
||||
for item from 'A' upto ('A'+15) do
|
||||
if set & 1 /= 0 then write(item) fi;
|
||||
set := set >> 1
|
||||
od;
|
||||
write(')')
|
||||
corp
|
||||
|
||||
proc consolidate([*]Set sets) word:
|
||||
word i, j, n;
|
||||
bool change;
|
||||
n := dim(sets, 1);
|
||||
|
||||
change := true;
|
||||
while change do
|
||||
change := false;
|
||||
for i from 0 upto n-1 do
|
||||
for j from i+1 upto n-1 do
|
||||
if sets[i] & sets[j] /= 0 then
|
||||
sets[i] := sets[i] | sets[j];
|
||||
sets[j] := 0;
|
||||
change := true
|
||||
fi
|
||||
od
|
||||
od
|
||||
od;
|
||||
|
||||
for i from 1 upto n-1 do
|
||||
if sets[i] = 0 then
|
||||
for j from i+1 upto n-1 do
|
||||
sets[j-1] := sets[j]
|
||||
od
|
||||
fi
|
||||
od;
|
||||
|
||||
i := 0;
|
||||
while i<n and sets[i] /= 0 do i := i+1 od;
|
||||
i
|
||||
corp
|
||||
|
||||
proc test([*]Set sets) void:
|
||||
word i, n;
|
||||
n := dim(sets, 1);
|
||||
for i from 0 upto n-1 do write_set(sets[i]) od;
|
||||
write(" -> ");
|
||||
n := consolidate(sets);
|
||||
for i from 0 upto n-1 do write_set(sets[i]) od;
|
||||
writeln()
|
||||
corp
|
||||
|
||||
proc main() void:
|
||||
[2]Set ex1;
|
||||
[2]Set ex2;
|
||||
[3]Set ex3;
|
||||
[5]Set ex4;
|
||||
|
||||
ex1[0]:=make_set("AB"); ex1[1]:=make_set("CD");
|
||||
ex2[0]:=make_set("AB"); ex2[1]:=make_set("BC");
|
||||
ex3[0]:=make_set("AB"); ex3[1]:=make_set("CD"); ex3[2]:=make_set("DB");
|
||||
ex4[0]:=make_set("HIK"); ex4[1]:=make_set("AB"); ex4[2]:=make_set("CD");
|
||||
ex4[3]:=make_set("DB"); ex4[4]:=make_set("FGH");
|
||||
|
||||
test(ex1);
|
||||
test(ex2);
|
||||
test(ex3);
|
||||
test(ex4);
|
||||
corp
|
||||
Loading…
Add table
Add a link
Reference in a new issue