gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: db836f4)
raw | patch | inline | side by side (parent: db836f4)
author | Doni Pracner <quinnuendo@gmail.com> | |
Mon, 21 Oct 2013 12:42:25 +0000 (14:42 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Mon, 21 Oct 2013 12:42:25 +0000 (14:42 +0200) |
25 files changed:
Cas01/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas01/RECNIKAT.DEF | [new file with mode: 0644] | patch | blob |
Cas01/RECNIKAT.MOD | [new file with mode: 0644] | patch | blob |
Cas01/RECNIKTE.MOD | [new file with mode: 0644] | patch | blob |
Cas02/MALA.SLI | [new file with mode: 0644] | patch | blob |
Cas02/PODSLIKA.MOD | [new file with mode: 0644] | patch | blob |
Cas02/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas02/VELIKA.SLI | [new file with mode: 0644] | patch | blob |
Cas03/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas03/SHAKER.MOD | [new file with mode: 0644] | patch | blob |
Cas05/NBROJEVA.MOD | [new file with mode: 0644] | patch | blob |
Cas05/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas06/NIZDIN.MOD | [new file with mode: 0644] | patch | blob |
Cas06/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas07/MAXZBIR.MOD | [new file with mode: 0644] | patch | blob |
Cas07/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas08/BOJENJE.MOD | [new file with mode: 0644] | patch | blob |
Cas08/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas09/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas09/Put.MOD | [new file with mode: 0644] | patch | blob |
Cas10/PERMP.MOD | [new file with mode: 0644] | patch | blob |
Cas10/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas11/Prezentacija.ppt | [new file with mode: 0644] | patch | blob |
Cas11/QUEENS.MOD | [new file with mode: 0644] | patch | blob |
Cas11/RESENJE.TXT | [new file with mode: 0644] | patch | blob |
diff --git a/Cas01/Prezentacija.ppt b/Cas01/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..6ff7ded
Binary files /dev/null and b/Cas01/Prezentacija.ppt differ
index 0000000..6ff7ded
Binary files /dev/null and b/Cas01/Prezentacija.ppt differ
diff --git a/Cas01/RECNIKAT.DEF b/Cas01/RECNIKAT.DEF
--- /dev/null
+++ b/Cas01/RECNIKAT.DEF
@@ -0,0 +1,42 @@
+DEFINITION MODULE RecnikATP;\r
+\r
+ CONST\r
+ Broj = 11; (* Neki prost broj *)\r
+ MaxDuzRec = 50;\r
+ MaxTabela = Broj - 1;\r
+\r
+ TYPE\r
+ String = ARRAY [1 .. MaxDuzRec] OF CHAR;\r
+ Lista = POINTER TO Element;\r
+ Element = RECORD\r
+ Veza, Prevod: Lista;\r
+ Rec: String;\r
+ END;\r
+ Indeksi = [0 .. MaxTabela];\r
+ Tabela = ARRAY Indeksi OF Lista;\r
+ Recnik = RECORD\r
+ BrojReci: CARDINAL;\r
+ Domace, Strane: Tabela;\r
+ END;\r
+\r
+ PROCEDURE Inicijalizuj(VAR R: Recnik);\r
+ PROCEDURE Unisti(VAR R: Recnik);\r
+\r
+ PROCEDURE Ubaci(DomacaRec, StranaRec: String;\r
+ VAR R: Recnik;\r
+ VAR Duplikat: BOOLEAN);\r
+\r
+ PROCEDURE Izbaci(Rec: String;\r
+ VAR R: Recnik;\r
+ Domaca: BOOLEAN;\r
+ VAR Ok: BOOLEAN);\r
+\r
+ PROCEDURE Prevedi(StranaNaDomacu: BOOLEAN;\r
+ Rec: String;\r
+ VAR Prevod: String;\r
+ VAR R: Recnik;\r
+ VAR Ok: BOOLEAN);\r
+\r
+ PROCEDURE Sadrzaj(VAR R: Recnik);\r
+\r
+END RecnikATP.\r
diff --git a/Cas01/RECNIKAT.MOD b/Cas01/RECNIKAT.MOD
--- /dev/null
+++ b/Cas01/RECNIKAT.MOD
@@ -0,0 +1,186 @@
+IMPLEMENTATION MODULE RecnikATP;\r
+\r
+ FROM IO IMPORT\r
+ RdKey, WrStr, WrLn, WrCard;\r
+ FROM SYSTEM IMPORT\r
+ TSIZE;\r
+ FROM Str IMPORT\r
+ Compare;\r
+ FROM Storage IMPORT\r
+ ALLOCATE, DEALLOCATE;\r
+\r
+ PROCEDURE Hash(Rec: String): Indeksi;\r
+ VAR\r
+ i, Zbir, Temp: CARDINAL;\r
+ BEGIN\r
+ Zbir:= 0;\r
+ i:= 1;\r
+ WHILE (i <= MaxDuzRec) AND (Rec[i] # CHR(0)) DO\r
+ Temp:= (ORD(Rec[i]) * ORD(Rec[i])) MOD Broj;\r
+ Zbir:= (Zbir + Temp) MOD Broj;\r
+ INC(i);\r
+ END;\r
+ RETURN Zbir;\r
+ END Hash;\r
+\r
+ PROCEDURE Inicijalizuj(VAR R: Recnik);\r
+ VAR\r
+ i: Indeksi;\r
+ BEGIN\r
+ WITH R DO\r
+ BrojReci:= 0;\r
+ FOR i := 0 TO MaxTabela DO\r
+ NEW(Domace[i]);\r
+ Domace[i]^.Veza := Domace[i];\r
+ NEW(Strane[i]);\r
+ Strane[i]^.Veza := Strane[i]\r
+ END;\r
+ END;\r
+ END Inicijalizuj;\r
+\r
+ PROCEDURE Unisti(VAR R: Recnik);\r
+ VAR\r
+ i: Indeksi;\r
+ Tekuci: Lista;\r
+ BEGIN\r
+ FOR i:= 0 TO MaxTabela DO\r
+ WHILE R.Domace[i] # R.Domace[i]^.Veza DO\r
+ Tekuci:= R.Domace[i]^.Veza;\r
+ R.Domace[i]^.Veza:= Tekuci^.Veza;\r
+ DISPOSE(Tekuci);\r
+ END;\r
+ DISPOSE(R.Domace[i]);\r
+ WHILE R.Strane[i] # R.Strane[i]^.Veza DO\r
+ Tekuci:= R.Strane[i]^.Veza;\r
+ R.Strane[i]^.Veza:= Tekuci^.Veza;\r
+ DISPOSE(Tekuci);\r
+ END;\r
+ DISPOSE(R.Strane[i]);\r
+ END;\r
+ END Unisti;\r
+\r
+ PROCEDURE Nadji(VAR Rec: String;\r
+ VAR Tab: Tabela;\r
+ VAR Prethodni: Lista;\r
+ VAR Nadjen: BOOLEAN);\r
+ VAR\r
+ Pozicija: Indeksi;\r
+ BEGIN\r
+ Pozicija:= Hash(Rec);\r
+ Prethodni:= Tab[Pozicija];\r
+ Prethodni^.Rec:= Rec;\r
+ IF Prethodni^.Veza = Prethodni THEN\r
+ Nadjen:= FALSE;\r
+ ELSE\r
+ WHILE Compare(Prethodni^.Veza^.Rec, Rec) # 0 DO\r
+ Prethodni:= Prethodni^.Veza;\r
+ END;\r
+ Nadjen:= Prethodni^.Veza # Tab[Pozicija]\r
+ END;\r
+ END Nadji;\r
+\r
+ PROCEDURE Ubaci(DomacaRec, StranaRec: String;\r
+ VAR R: Recnik;\r
+ VAR Duplikat: BOOLEAN);\r
+ VAR\r
+ NadjenDom, NadjenStr: BOOLEAN;\r
+ PrethodniDom, PrethodniStr, PomDom, PomStr: Lista;\r
+ BEGIN\r
+\r
+ Nadji(DomacaRec, R.Domace, PrethodniDom, NadjenDom);\r
+ Nadji(StranaRec, R.Strane, PrethodniStr, NadjenStr);\r
+\r
+ IF NadjenDom OR NadjenStr THEN\r
+ Duplikat:= TRUE;\r
+ ELSE\r
+\r
+ Duplikat := FALSE;\r
+\r
+ NEW(PomDom);\r
+ PomDom^.Rec:= DomacaRec;\r
+ PomDom^.Veza:= PrethodniDom^.Veza;\r
+ PrethodniDom^.Veza:= PomDom;\r
+\r
+ NEW(PomStr);\r
+ PomStr^.Rec:= StranaRec;\r
+ PomStr^.Veza:= PrethodniStr^.Veza;\r
+ PrethodniStr^.Veza:= PomStr;\r
+\r
+ PomDom^.Prevod:= PomStr;\r
+ PomStr^.Prevod:= PomDom;\r
+\r
+ INC(R.BrojReci);\r
+\r
+ END;\r
+ END Ubaci;\r
+\r
+ PROCEDURE Izbaci(Rec: String;\r
+ VAR R: Recnik;\r
+ Domaca: BOOLEAN;\r
+ VAR Ok: BOOLEAN);\r
+ VAR\r
+ Prethodni, Prethodni2, Temp, Temp2: Lista;\r
+ BEGIN\r
+\r
+ IF Domaca THEN\r
+ Nadji(Rec, R.Domace, Prethodni, Ok);\r
+ ELSE\r
+ Nadji(Rec, R.Strane, Prethodni, Ok);\r
+ END;\r
+\r
+ IF Ok THEN\r
+\r
+ Temp:= Prethodni^.Veza;\r
+ Prethodni^.Veza:= Temp^.Veza;\r
+\r
+ Temp2:= Temp^.Prevod;\r
+ Prethodni2:= Temp2^.Veza;\r
+ WHILE Prethodni2^.Veza # Temp2 DO\r
+ Prethodni2:= Prethodni2^.Veza;\r
+ END;\r
+ Prethodni2^.Veza:= Temp2^.Veza;\r
+\r
+ DISPOSE(Temp);\r
+ DISPOSE(Temp2);\r
+\r
+ DEC(R.BrojReci);\r
+ END;\r
+ END Izbaci;\r
+\r
+ PROCEDURE Prevedi(StranuNaDomacu: BOOLEAN;\r
+ Rec: String;\r
+ VAR Prevod: String;\r
+ VAR R: Recnik;\r
+ VAR Ok: BOOLEAN);\r
+ VAR\r
+ Prethodni: Lista;\r
+ BEGIN\r
+ IF StranuNaDomacu THEN\r
+ Nadji(Rec, R.Strane, Prethodni, Ok);\r
+ ELSE\r
+ Nadji(Rec, R.Domace, Prethodni, Ok);\r
+ END;\r
+ IF Ok THEN\r
+ Prevod:= Prethodni^.Veza^.Prevod^.Rec;\r
+ END\r
+ END Prevedi;\r
+\r
+ PROCEDURE Sadrzaj(VAR R: Recnik);\r
+ VAR\r
+ i: Indeksi;\r
+ Tekuci: Lista;\r
+ BEGIN\r
+ WrStr('Sadrzaj recnika:');\r
+ FOR i:= 0 TO MaxTabela DO\r
+ Tekuci:= R.Domace[i]^.Veza;\r
+ WHILE Tekuci# R.Domace[i] DO\r
+ WrLn;\r
+ WrStr(Tekuci^.Rec);\r
+ WrStr(' --------- ');\r
+ WrStr(Tekuci^.Prevod^.Rec);\r
+ Tekuci:= Tekuci^.Veza;\r
+ END;\r
+ END;\r
+ END Sadrzaj;\r
+\r
+END RecnikATP.\r
diff --git a/Cas01/RECNIKTE.MOD b/Cas01/RECNIKTE.MOD
--- /dev/null
+++ b/Cas01/RECNIKTE.MOD
@@ -0,0 +1,116 @@
+MODULE RecnikTest;\r
+\r
+ FROM RecnikATP IMPORT\r
+ String, Recnik, Inicijalizuj, Ubaci, Izbaci, Sadrzaj, Prevedi, Unisti;\r
+ FROM IO IMPORT\r
+ WrLn, WrStr, RdStr, WrCard, RdKey, WrChar;\r
+ FROM Window IMPORT\r
+ Clear;\r
+\r
+ VAR\r
+ R: Recnik;\r
+ Rec, Prevod: String;\r
+ Izbor, Izb: CHAR;\r
+ Ok, Duplikat, Domaca, StrNaDom: BOOLEAN;\r
+\r
+ PROCEDURE Meni(VAR Izbor: CHAR);\r
+ TYPE\r
+ Slova = SET OF CHAR;\r
+ VAR\r
+ i: CARDINAL;\r
+ BEGIN\r
+ Clear;\r
+ FOR i:= 1 TO 8 DO\r
+ WrLn;\r
+ END;\r
+ WrStr(' P --- prevod reci'); WrLn;\r
+ WrStr(' B --- broj reci u recniku'); WrLn;\r
+ WrStr(' U --- ubacivanje nove reci i njenog prevoda u recnik'); WrLn;\r
+ WrStr(' I --- izbacivanje reci i njenog prevoda iz recnika'); WrLn;\r
+ WrStr(' S --- sekvencijalni prikaz recnika'); WrLn;\r
+ WrStr(' Q --- kraj rada');\r
+ REPEAT\r
+ Izbor:= CAP(RdKey());\r
+ UNTIL Izbor IN Slova {'P', 'B', 'U', 'I', 'S', 'Q'};\r
+ Clear;\r
+ END Meni;\r
+\r
+ PROCEDURE Pauza;\r
+ VAR\r
+ Ch: CHAR;\r
+ BEGIN\r
+ Ch:= RdKey();\r
+ END Pauza;\r
+\r
+BEGIN\r
+ Inicijalizuj(R);\r
+ REPEAT\r
+ Meni(Izbor);\r
+ CASE Izbor OF\r
+ 'P': REPEAT\r
+ WrStr('1) prevod strane reci'); WrLn;\r
+ WrStr('2) prevod domace reci'); WrLn;\r
+ WrLn;\r
+ WrStr("Unesite '1' ili '2' --- ");\r
+ Izb:= RdKey();\r
+ WrChar(Izb); WrLn;\r
+ UNTIL (Izb = '1') OR (Izb = '2');\r
+ StrNaDom:= Izb = '1';\r
+ IF StrNaDom THEN\r
+ WrStr('Unesite stranu rec ---- ');\r
+ RdStr(Rec);\r
+ Prevedi(StrNaDom, Rec, Prevod, R, Ok);\r
+ IF Ok THEN\r
+ WrStr('Prevod ---------------- ');\r
+ WrStr(Prevod);\r
+ ELSE\r
+ WrStr('Zadata rec se ne nalazi u recniku.');\r
+ END;\r
+ ELSE\r
+ WrStr('Unesite domacu rec ---- ');\r
+ RdStr(Rec);\r
+ Prevedi(StrNaDom, Rec, Prevod, R, Ok);\r
+ IF Ok THEN\r
+ WrStr('Prevod ---------------- ');\r
+ WrStr(Prevod);\r
+ ELSE\r
+ WrStr('Zadata rec se ne nalazi u recniku.');\r
+ END;\r
+ END;\r
+ Pauza; |\r
+ 'B': WrStr('Recnik raspolaze fondom od ');\r
+ WrCard(R.BrojReci, 1);\r
+ WrStr(' reci.');\r
+ Pauza; |\r
+ 'U': WrStr('Unesite novu domacu rec ----- ');\r
+ RdStr(Rec);\r
+ WrStr('Unesite njen prevod -------- ');\r
+ RdStr(Prevod);\r
+ Ubaci(Rec, Prevod, R, Duplikat);\r
+ IF Duplikat THEN\r
+ WrStr('U recniku se vec nalazi data rec.');\r
+ ELSE\r
+ WrStr('Upisano.');\r
+ END;\r
+ Pauza; |\r
+ 'I': WrStr('Unesite rec --- ');\r
+ RdStr(Rec);\r
+ REPEAT\r
+ WrStr('Da li je uneta rec domaca ili strana? (d/s) ');\r
+ Izb:= RdKey();\r
+ WrLn;\r
+ UNTIL (CAP(Izb) = 'D') OR (CAP(Izb) = 'S');\r
+ Domaca:= CAP(Izb) = 'D';\r
+ Izbaci(Rec, R, Domaca, Ok);\r
+ IF Ok THEN\r
+ WrStr('Izbrisano.')\r
+ ELSE\r
+ WrStr('Rec se nije ni nalazila u recniku.')\r
+ END;\r
+ Pauza; |\r
+ 'S': Sadrzaj(R);\r
+ Pauza;\r
+ END;\r
+ UNTIL Izbor = 'Q';\r
+ Unisti(R);\r
+END RecnikTest.\r
diff --git a/Cas02/MALA.SLI b/Cas02/MALA.SLI
--- /dev/null
+++ b/Cas02/MALA.SLI
@@ -0,0 +1,6 @@
+5\r
+ 0 0 1 0 0\r
+ 0 1 1 1 0\r
+ 1 1 2 1 1\r
+ 0 1 1 1 0\r
+ 0 0 1 0 0\r
diff --git a/Cas02/PODSLIKA.MOD b/Cas02/PODSLIKA.MOD
--- /dev/null
+++ b/Cas02/PODSLIKA.MOD
@@ -0,0 +1,168 @@
+MODULE Podslika;\r
+\r
+ FROM FIO IMPORT\r
+ File, Open, Close, RdCard, EOF, OK, Exists;\r
+ FROM IO IMPORT\r
+ WrLn, WrStr, WrCard;\r
+\r
+ CONST\r
+ MaxDim = 100;\r
+ BrojBoja = 16;\r
+ Osnova = MaxDim * (BrojBoja - 1) + 1;\r
+ ProstBroj = 3001;\r
+ ImeVel = 'Velika.Sli';\r
+ ImeMal = 'Mala.Sli';\r
+\r
+ TYPE\r
+ Boja = [0 .. BrojBoja - 1];\r
+ Slika = ARRAY [1 .. MaxDim], [1 .. MaxDim] OF Boja;\r
+\r
+ VAR\r
+ Velika, Mala: Slika;\r
+ DimVel, DimMal, Vr, Ko: CARDINAL;\r
+ KljucMale, KljucSegmenta, Stepen: LONGCARD;\r
+ Ok, Iste: BOOLEAN;\r
+\r
+ PROCEDURE Citaj(VAR Slika: Slika;\r
+ Ime: ARRAY OF CHAR;\r
+ VAR Dim: CARDINAL;\r
+ VAR Ok: BOOLEAN);\r
+ VAR\r
+ F: File;\r
+ Vr, Ko: CARDINAL;\r
+ Jos: BOOLEAN;\r
+ BEGIN\r
+ Ok:= Ok AND Exists(Ime);\r
+ IF Ok THEN\r
+ F:= Open(Ime);\r
+ Dim:= RdCard(F);\r
+ Vr:= 1;\r
+ Jos:= TRUE;\r
+ WHILE Jos AND (Vr <= Dim) DO\r
+ Ko:= 1;\r
+ WHILE Jos AND (Ko <= Dim) DO\r
+ Slika[Vr, Ko]:= RdCard(F);\r
+ Ok:= Ok AND (Slika[Vr, Ko] < BrojBoja);\r
+ Jos:= Ok AND NOT EOF;\r
+ INC(Ko);\r
+ END;\r
+ INC(Vr);\r
+ END;\r
+ Close(F);\r
+ ELSE\r
+ Dim:= 0;\r
+ END;\r
+ END Citaj;\r
+\r
+ PROCEDURE Proveri(VAR Velika, Mala: Slika;\r
+ DimMal, Vr, Ko: CARDINAL): BOOLEAN;\r
+ VAR\r
+ i, j: CARDINAL;\r
+ Iste: BOOLEAN;\r
+ BEGIN\r
+ Iste:= TRUE;\r
+ i:= 1;\r
+ WHILE Iste AND (i <= DimMal) DO\r
+ j:= 1;\r
+ WHILE Iste AND (j <= DimMal) DO\r
+ IF Mala[i, j] # Velika[Vr + i - 1, Ko + j - 1] THEN\r
+ Iste:= FALSE;\r
+ END;\r
+ INC(j);\r
+ END;\r
+ INC(i);\r
+ END;\r
+ RETURN Iste;\r
+ END Proveri;\r
+\r
+ PROCEDURE Hash(S: Slika; DimMal, Vr: CARDINAL): LONGCARD;\r
+ VAR\r
+ i, j: CARDINAL;\r
+ Kljuc, ZbirKolone, Temp: LONGCARD;\r
+ BEGIN\r
+\r
+ Stepen:= 1;\r
+ Kljuc:= 0;\r
+\r
+ FOR i:= DimMal TO 1 BY -1 DO\r
+\r
+ ZbirKolone:= 0;\r
+ FOR j:= Vr TO Vr + DimMal - 1 DO\r
+ ZbirKolone:= ZbirKolone + LONGCARD(S[j, i]);\r
+ END;\r
+\r
+ Temp:= (ZbirKolone * Stepen) MOD ProstBroj;\r
+ Kljuc:= (Kljuc + Temp) MOD ProstBroj;\r
+ Stepen:= (Stepen * Osnova) MOD ProstBroj;\r
+\r
+ END;\r
+\r
+ Stepen:= Stepen DIV Osnova;\r
+\r
+ RETURN Kljuc;\r
+\r
+ END Hash;\r
+\r
+ PROCEDURE DoterajHash(S: Slika; DimMal, Vr, Ko: CARDINAL;\r
+ VAR Kljuc: LONGCARD);\r
+ VAR\r
+ i, j: CARDINAL;\r
+ ZbirKolone, Temp: LONGCARD;\r
+ BEGIN\r
+\r
+ ZbirKolone:= 0;\r
+ FOR j:= Vr TO Vr + DimMal - 1 DO\r
+ ZbirKolone:= ZbirKolone + LONGCARD(S[j, Ko - 1]);\r
+ END;\r
+\r
+ Temp:= (ZbirKolone * Stepen) MOD ProstBroj;\r
+\r
+ IF Kljuc >= Temp THEN\r
+ Kljuc:= Kljuc - Temp;\r
+ ELSE\r
+ Kljuc:= Kljuc + ProstBroj - Temp;\r
+ END;\r
+\r
+ Kljuc:= (Kljuc * Osnova) MOD ProstBroj;\r
+\r
+ ZbirKolone:= 0;\r
+ FOR j:= Vr TO Vr + DimMal - 1 DO\r
+ ZbirKolone:= ZbirKolone + LONGCARD(S[j, Ko + DimMal - 1]);\r
+ END;\r
+\r
+ Kljuc:= (Kljuc + ZbirKolone) MOD ProstBroj;\r
+\r
+ END DoterajHash;\r
+\r
+BEGIN\r
+ Ok:= TRUE;\r
+ Citaj(Velika, ImeVel, DimVel, Ok);\r
+ Citaj(Mala, ImeMal, DimMal, Ok);\r
+ IF Ok THEN\r
+ KljucMale:= Hash(Mala, DimMal, 1);\r
+ FOR Vr:= 1 TO (DimVel - DimMal + 1) DO\r
+ KljucSegmenta:= Hash(Velika, DimMal, Vr);\r
+ IF (KljucMale = KljucSegmenta) THEN\r
+ Iste:= Proveri(Velika, Mala, DimMal, Vr, 1);\r
+ IF Iste THEN\r
+ WrLn;\r
+ WrStr('Podslika je nadjena. Pocinje na poziciji (');\r
+ WrCard(Vr, 1); WrStr(', '); WrCard(1, 1); WrStr(')');\r
+ END;\r
+ END;\r
+ FOR Ko:= 2 TO (DimVel - DimMal + 1) DO\r
+ DoterajHash(Velika, DimMal, Vr, Ko, KljucSegmenta);\r
+ IF (KljucMale = KljucSegmenta) THEN\r
+ Iste:= Proveri(Velika, Mala, DimMal, Vr, Ko);\r
+ IF Iste THEN\r
+ WrLn;\r
+ WrStr('Podslika je nadjena. Pocinje na poziciji (');\r
+ WrCard(Vr, 1); WrStr(', '); WrCard(Ko, 1); WrStr(')');\r
+ END;\r
+ END;\r
+ END;\r
+ END;\r
+ ELSE\r
+ WrStr('Greska u citanju fajla.');\r
+ END;\r
+END Podslika.\r
diff --git a/Cas02/Prezentacija.ppt b/Cas02/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..0c685f2
Binary files /dev/null and b/Cas02/Prezentacija.ppt differ
index 0000000..0c685f2
Binary files /dev/null and b/Cas02/Prezentacija.ppt differ
diff --git a/Cas02/VELIKA.SLI b/Cas02/VELIKA.SLI
--- /dev/null
+++ b/Cas02/VELIKA.SLI
@@ -0,0 +1,13 @@
+12\r
+ 0 0 0 0 0 0 0 0 0 0 0 0\r
+ 0 0 0 0 0 0 0 0 0 0 0 0\r
+ 0 0 0 1 0 0 0 0 0 0 0 0\r
+ 0 0 1 1 1 0 0 0 0 0 0 0\r
+ 0 1 1 2 1 1 0 0 0 0 0 0\r
+ 0 0 1 1 1 0 5 5 5 0 0 0\r
+ 0 0 0 1 0 0 0 0 0 0 0 0\r
+ 0 0 0 0 0 5 0 0 1 0 0 0\r
+ 0 0 0 0 5 0 0 1 2 1 0 0\r
+ 0 0 0 5 0 0 1 2 15 2 1 0\r
+ 0 0 5 0 0 0 0 1 2 1 0 0\r
+ 0 0 0 0 0 0 0 0 1 0 0 0\r
diff --git a/Cas03/Prezentacija.ppt b/Cas03/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..d059c40
Binary files /dev/null and b/Cas03/Prezentacija.ppt differ
index 0000000..d059c40
Binary files /dev/null and b/Cas03/Prezentacija.ppt differ
diff --git a/Cas03/SHAKER.MOD b/Cas03/SHAKER.MOD
--- /dev/null
+++ b/Cas03/SHAKER.MOD
@@ -0,0 +1,80 @@
+MODULE Shaker;\r
+\r
+ FROM IO IMPORT\r
+ WrCard, WrStr, RdCard, WrLn, OK;\r
+\r
+ CONST\r
+ Max = 10;\r
+\r
+ TYPE\r
+ Indeks = [1 .. Max];\r
+ NizTip = ARRAY Indeks OF CARDINAL;\r
+\r
+ VAR\r
+ Niz: NizTip;\r
+\r
+ PROCEDURE Unos(VAR Niz: NizTip);\r
+ VAR\r
+ i: Indeks;\r
+ BEGIN\r
+ FOR i:= 1 TO Max DO\r
+ REPEAT\r
+ WrStr('Unesite ');\r
+ WrCard(i, 2);\r
+ WrStr('. clan niza: ');\r
+ Niz[i]:= RdCard();\r
+ WrLn;\r
+ UNTIL OK;\r
+ END;\r
+ END Unos;\r
+\r
+ PROCEDURE Ispis(VAR Niz: NizTip);\r
+ VAR\r
+ i: Indeks;\r
+ BEGIN\r
+ FOR i := 1 TO Max - 1 DO\r
+ WrCard(Niz[i], 1);\r
+ WrStr(', ');\r
+ END;\r
+ WrCard(Niz[Max], 1);\r
+ END Ispis;\r
+\r
+ PROCEDURE ShakerSort(VAR Niz: NizTip);\r
+ VAR\r
+ Levi, Desni, i, ZadnjiMenjan: Indeks;\r
+ Temp: CARDINAL;\r
+ BEGIN\r
+ Levi:= 2;\r
+ Desni:= Max;\r
+ ZadnjiMenjan:= Max;\r
+ REPEAT\r
+ FOR i:= Desni TO Levi BY -1 DO\r
+ IF Niz[i - 1] > Niz[i] THEN\r
+ Temp:= Niz[i - 1];\r
+ Niz[i - 1]:= Niz[i];\r
+ Niz[i]:= Temp;\r
+ ZadnjiMenjan:= i;\r
+ END;\r
+ END;\r
+ Levi:= ZadnjiMenjan + 1;\r
+ FOR i:= Levi TO Desni DO\r
+ IF Niz[i - 1] > Niz[i] THEN\r
+ Temp:= Niz[i - 1];\r
+ Niz[i - 1]:= Niz[i];\r
+ Niz[i]:= Temp;\r
+ ZadnjiMenjan:= i;\r
+ END;\r
+ END;\r
+ Desni:= ZadnjiMenjan - 1;\r
+ UNTIL Levi > Desni;\r
+ END ShakerSort;\r
+\r
+BEGIN\r
+ Unos(Niz);\r
+ WrStr('Unesen niz: ');\r
+ Ispis(Niz);\r
+ WrLn;\r
+ WrStr('Sortiran niz: ');\r
+ ShakerSort(Niz);\r
+ Ispis(Niz);\r
+END Shaker.\r
diff --git a/Cas05/NBROJEVA.MOD b/Cas05/NBROJEVA.MOD
--- /dev/null
+++ b/Cas05/NBROJEVA.MOD
@@ -0,0 +1,112 @@
+MODULE NBrojeva;\r
+\r
+ FROM IO IMPORT\r
+ WrLn, WrCard, RdCard, WrStr;\r
+\r
+ CONST\r
+ MaxNiz = 50;\r
+ MaxSuma = 500;\r
+\r
+ VAR\r
+ n, Suma, SumaPola: CARDINAL;\r
+ Broj: ARRAY [1 .. MaxNiz] OF CARDINAL;\r
+ Iskor: ARRAY[1 .. MaxNiz] OF BOOLEAN;\r
+ Mat: ARRAY[0 .. MaxSuma], [0 .. MaxNiz] OF CARDINAL;\r
+ (* Mat[i, j] je suma brojeva u resenju ako je maksimalna *)\r
+ (* dozvoljena suma brojeva u resenju jednaka 'i' i ako se *)\r
+ (* koristi samo prvih 'j' brojeva. *)\r
+\r
+ PROCEDURE Unos;\r
+ VAR\r
+ i: CARDINAL;\r
+ BEGIN\r
+ WrStr('Unesite n: ');\r
+ n:= RdCard();\r
+ Suma:= 0;\r
+ FOR i:= 1 TO n DO\r
+ WrStr('Unesite ');\r
+ WrCard(i, 1);\r
+ WrStr('. broj: ');\r
+ Broj[i]:= RdCard();\r
+ Suma:= Suma + Broj[i];\r
+ Iskor[i]:= FALSE;\r
+ END;\r
+ SumaPola:= Suma DIV 2;\r
+ END Unos;\r
+\r
+ PROCEDURE Resi;\r
+ VAR\r
+ i, j, Pom: CARDINAL;\r
+ BEGIN\r
+ FOR i:= 0 TO SumaPola DO\r
+ Mat[i, 0]:= 0; (* Koristi se prvih 0 brojeva *)\r
+ END;\r
+ FOR j:= 1 TO n DO\r
+ Mat[0, j]:= 0; (* Maksimalna dozvoljena suma brojeva u resenju je 0 *)\r
+ END;\r
+ FOR i:= 1 TO SumaPola DO\r
+ (* Maks. dozvoljena suma brojeva u resenju je i *)\r
+ FOR j := 1 TO n DO\r
+ (* U resenju mogu ucestvovati prvih j brojeva *)\r
+ Mat[i, j]:= Mat[i, j - 1];\r
+ IF Broj[j] <= i THEN\r
+ Pom:= Mat[i - Broj[j], j - 1] + Broj[j];\r
+ IF Pom > Mat[i, j] THEN\r
+ Mat[i, j]:= Pom;\r
+ END;\r
+ END;\r
+ END;\r
+ END;\r
+ END Resi;\r
+\r
+ PROCEDURE IspisiPrvu;\r
+ VAR\r
+ i, j: CARDINAL;\r
+ BEGIN\r
+ WrStr('Zbir prve grupe brojeva je ');\r
+ WrCard(Mat[SumaPola, n], 1);\r
+ WrLn;\r
+ WrStr('Prvu grupu brojeva cine brojevi:');\r
+ WrLn;\r
+ i:= SumaPola;\r
+ j:= n;\r
+ REPEAT\r
+ WHILE (j > 0) AND (Mat[i, j] = Mat[i, j - 1]) DO\r
+ DEC(j);\r
+ END;\r
+ IF j > 0 THEN\r
+ WrCard(Broj[j], 8);\r
+ Iskor[j]:= TRUE;\r
+ i:= i - Broj[j];\r
+ DEC(j);\r
+ END;\r
+ UNTIL j = 0;\r
+ END IspisiPrvu;\r
+\r
+ PROCEDURE IspisiDrugu;\r
+ VAR\r
+ i, j: CARDINAL;\r
+ BEGIN\r
+ WrLn;\r
+ WrStr('Zbir druge grupe brojeva je ');\r
+ WrCard(Suma - Mat[SumaPola, n], 1);\r
+ WrLn;\r
+ WrStr('Drugu grupu brojeva cine brojevi:');\r
+ WrLn;\r
+ FOR i := 1 TO n DO\r
+ IF NOT Iskor[i] THEN\r
+ WrCard(Broj[i], 8);\r
+ END;\r
+ END;\r
+ END IspisiDrugu;\r
+\r
+BEGIN\r
+ Unos;\r
+ IF SumaPola > MaxSuma THEN\r
+ WrStr('Ulazni podaci su suvise veliki.');\r
+ ELSE\r
+ Resi;\r
+ IspisiPrvu;\r
+ IspisiDrugu;\r
+ END;\r
+END NBrojeva.\r
diff --git a/Cas05/Prezentacija.ppt b/Cas05/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..a1b04ab
Binary files /dev/null and b/Cas05/Prezentacija.ppt differ
index 0000000..a1b04ab
Binary files /dev/null and b/Cas05/Prezentacija.ppt differ
diff --git a/Cas06/NIZDIN.MOD b/Cas06/NIZDIN.MOD
--- /dev/null
+++ b/Cas06/NIZDIN.MOD
@@ -0,0 +1,65 @@
+MODULE NizDin;\r
+\r
+ FROM IO IMPORT\r
+ WrStr, RdInt, WrInt;\r
+\r
+ CONST\r
+ MaxN = 1000;\r
+\r
+ VAR\r
+ a, b: ARRAY [0 .. MaxN] OF INTEGER;\r
+ (* b[i] je suma elemenata u resenju za *)\r
+ (* deo niza 'a' do 'i'-tog elementa *)\r
+ n: INTEGER;\r
+\r
+ PROCEDURE Unos;\r
+ VAR\r
+ i: CARDINAL;\r
+ BEGIN\r
+ WrStr('Unesite N: ');\r
+ n:= RdInt();\r
+ FOR i:= 1 TO n DO\r
+ WrStr('A[');\r
+ WrInt(i, 1);\r
+ WrStr('] = ');\r
+ a[i]:= RdInt();\r
+ END;\r
+ END Unos;\r
+ \r
+ PROCEDURE Resi;\r
+ VAR\r
+ i, j, Pom: CARDINAL;\r
+ BEGIN\r
+ b[0]:= 0;\r
+ IF a[1] > 0 THEN\r
+ b[1]:= a[1];\r
+ ELSE\r
+ b[1]:= 0;\r
+ END;\r
+ FOR i:= 2 TO n DO\r
+ IF b[i - 2] + a[i] > b[i - 1] THEN\r
+ b[i]:= b[i - 2] + a[i];\r
+ ELSE\r
+ b[i]:= b[i - 1];\r
+ END\r
+ END;\r
+ END Resi;\r
+\r
+ PROCEDURE Ispis(n: CARDINAL);\r
+ BEGIN\r
+ IF n > 0 THEN\r
+ IF b[n] = b[n - 1] THEN\r
+ Ispis(n - 1);\r
+ ELSE\r
+ Ispis(n - 2);\r
+ WrInt(a[n], 8);\r
+ END;\r
+ END;\r
+ END Ispis;\r
+\r
+BEGIN\r
+ Unos;\r
+ Resi;\r
+ WrStr('Podniz: ');\r
+ Ispis(n);\r
+END NizDin.\r
diff --git a/Cas06/Prezentacija.ppt b/Cas06/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..c0ab24e
Binary files /dev/null and b/Cas06/Prezentacija.ppt differ
index 0000000..c0ab24e
Binary files /dev/null and b/Cas06/Prezentacija.ppt differ
diff --git a/Cas07/MAXZBIR.MOD b/Cas07/MAXZBIR.MOD
--- /dev/null
+++ b/Cas07/MAXZBIR.MOD
@@ -0,0 +1,100 @@
+MODULE MaxZbir;\r
+\r
+ FROM IO IMPORT\r
+ WrStr, WrLn, WrCard, WrInt, RdCard, RdInt;\r
+\r
+ CONST\r
+ Max = 100;\r
+\r
+ VAR\r
+ A, B: ARRAY [1 .. Max], [1 .. Max] OF INTEGER;\r
+ m, n: CARDINAL;\r
+ (* B[vr, ko] je vrednost optimalnog resenja od (1, 1) do (vr, ko) *)\r
+\r
+ PROCEDURE Unos;\r
+ VAR\r
+ i, j: CARDINAL;\r
+ BEGIN\r
+ WrStr('Unesite n: ');\r
+ n:= RdCard();\r
+ WrStr('Unesite m: ');\r
+ m:= RdCard();\r
+ IF (n < Max) AND (m < Max) THEN\r
+ FOR i:= 1 TO m DO\r
+ FOR j:= 1 TO n DO\r
+ WrStr('A[');\r
+ WrCard(i, 1);\r
+ WrStr(', ');\r
+ WrCard(j, 1);\r
+ WrStr('] = ');\r
+ A[i, j] := RdInt();\r
+ END;\r
+ END;\r
+ END;\r
+ END Unos;\r
+\r
+ PROCEDURE Resi;\r
+ VAR\r
+ i, j: CARDINAL;\r
+ BEGIN\r
+ B[1, 1]:= A[1, 1];\r
+ FOR j:= 2 TO n DO\r
+ B[1, j]:= A[1, j] + B[1, j-1];\r
+ END;\r
+ FOR i:= 2 TO m DO\r
+ B[i, 1]:= A[i, 1] + B[i-1, 1];\r
+ END;\r
+ FOR i:= 2 TO m DO\r
+ FOR j:= 2 TO n DO\r
+ IF B[i, j - 1] < B[i - 1, j] THEN\r
+ B[i, j]:= A[i, j] + B[i - 1, j];\r
+ ELSE\r
+ B[i, j]:= A[i, j] + B[i, j - 1];\r
+ END;\r
+ END;\r
+ END;\r
+ END Resi;\r
+\r
+ PROCEDURE Ispis(Vr, Ko: CARDINAL);\r
+ VAR\r
+ i: CARDINAL;\r
+ BEGIN\r
+ IF (Vr > 1) AND (Ko > 1) THEN\r
+ IF B[Vr - 1, Ko] > B[Vr, Ko - 1] THEN\r
+ Ispis(Vr - 1, Ko);\r
+ ELSE\r
+ Ispis(Vr, Ko - 1);\r
+ END;\r
+ WrStr('(');\r
+ WrCard(Vr, 1);\r
+ WrStr(', ');\r
+ WrCard(Ko, 1);\r
+ WrStr(')');\r
+ ELSIF Vr = 1 THEN\r
+ FOR i:= 1 TO Ko DO\r
+ WrStr('(1, ');\r
+ WrCard(i, 1);\r
+ WrStr(')');\r
+ END;\r
+ ELSE\r
+ FOR i:= 1 TO Vr DO\r
+ WrStr('(');\r
+ WrCard(i, 1);\r
+ WrStr(', 1)');\r
+ END;\r
+ END;\r
+ END Ispis;\r
+\r
+BEGIN\r
+ Unos;\r
+ IF (n < Max) AND (m < Max) THEN\r
+ Resi;\r
+ WrStr('Maksimalni zbir je ');\r
+ WrInt(B[m, n], 1);\r
+ WrStr(' a postize se ovako:');\r
+ WrLn;\r
+ Ispis(m, n)\r
+ ELSE\r
+ WrStr('Suvise velika matrica.')\r
+ END\r
+END MaxZbir.\r
diff --git a/Cas07/Prezentacija.ppt b/Cas07/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..3aab8ac
Binary files /dev/null and b/Cas07/Prezentacija.ppt differ
index 0000000..3aab8ac
Binary files /dev/null and b/Cas07/Prezentacija.ppt differ
diff --git a/Cas08/BOJENJE.MOD b/Cas08/BOJENJE.MOD
--- /dev/null
+++ b/Cas08/BOJENJE.MOD
@@ -0,0 +1,128 @@
+MODULE Bojenje;\r
+\r
+ FROM IO IMPORT\r
+ WrStr, WrLn, WrLngCard;\r
+\r
+ CONST\r
+ MaxBrojZemalja = 30;\r
+ DuzinaImena = 18;\r
+\r
+ TYPE\r
+ RangImena = [1 .. DuzinaImena];\r
+ Zemlja = [1 .. MaxBrojZemalja];\r
+ SkupZ = SET OF Zemlja;\r
+ Boja = (Crvena, Plava, Zelena, Zuta);\r
+ GraniceTip = ARRAY Zemlja OF SkupZ;\r
+ BojeZemalja = ARRAY Boja OF SkupZ;\r
+ ImenaZemalja = ARRAY Zemlja, RangImena OF CHAR;\r
+\r
+ VAR\r
+ Granice: GraniceTip;\r
+ Obojeno: BojeZemalja;\r
+ Ime: ImenaZemalja;\r
+ BrZ: Zemlja;\r
+ RBr: LONGCARD;\r
+\r
+ PROCEDURE Inicijalizacija;\r
+ VAR\r
+ i: Boja;\r
+ BEGIN\r
+ FOR i:= MIN(Boja) TO MAX(Boja) DO\r
+ Obojeno[i]:= SkupZ {};\r
+ END;\r
+ Ime[ 1]:= 'Maroko';\r
+ Ime[ 2]:= 'Zapadna Sahara';\r
+ Ime[ 3]:= 'Alzir';\r
+ Ime[ 4]:= 'Tunis';\r
+ Ime[ 5]:= 'Mauritanija';\r
+ Ime[ 6]:= 'Mali';\r
+ Ime[ 7]:= 'Niger';\r
+ Ime[ 8]:= 'Libija';\r
+ Ime[ 9]:= 'Senegal';\r
+ Ime[10]:= 'Gvineja';\r
+ Ime[11]:= 'Obala Slonovace';\r
+ Ime[12]:= 'Burkina Faso';\r
+ Ime[13]:= 'Benin';\r
+ Ime[14]:= 'Nigerija';\r
+ Ime[15]:= 'Cad';\r
+ Ime[16]:= 'Sudan';\r
+ Ime[17]:= 'Egipat';\r
+ Ime[18]:= 'Gambija';\r
+ Ime[19]:= 'Gvineja Bisao';\r
+ Ime[20]:= 'Siera Leone';\r
+ Granice[ 1]:= SkupZ {3, 2};\r
+ Granice[ 2]:= SkupZ {1, 3, 5};\r
+ Granice[ 3]:= SkupZ {1, 2, 5, 6, 7, 8, 4};\r
+ Granice[ 4]:= SkupZ {3, 8};\r
+ Granice[ 5]:= SkupZ {2, 3, 6, 9};\r
+ Granice[ 6]:= SkupZ {3, 5, 9, 10, 11, 12, 7};\r
+ Granice[ 7]:= SkupZ {3, 6, 12, 13, 14, 15, 8};\r
+ Granice[ 8]:= SkupZ {4, 3, 7, 15, 16, 17};\r
+ Granice[ 9]:= SkupZ {18, 19, 10, 6, 5};\r
+ Granice[10]:= SkupZ {19, 9, 6, 20, 11};\r
+ Granice[11]:= SkupZ {10, 6, 12};\r
+ Granice[12]:= SkupZ {6, 11, 13, 7};\r
+ Granice[13]:= SkupZ {12, 7, 14};\r
+ Granice[14]:= SkupZ {13, 7, 15};\r
+ Granice[15]:= SkupZ {14, 7, 8, 16};\r
+ Granice[16]:= SkupZ {17, 8, 15};\r
+ Granice[17]:= SkupZ {8, 15, 16};\r
+ Granice[18]:= SkupZ {9};\r
+ Granice[19]:= SkupZ {9, 10};\r
+ Granice[20]:= SkupZ {10};\r
+ RBr:= 0;\r
+ BrZ:= 20\r
+ END Inicijalizacija;\r
+\r
+ PROCEDURE StampajSkup(VAR S: SkupZ);\r
+ VAR\r
+ z: Zemlja;\r
+ Prvi: BOOLEAN;\r
+ BEGIN\r
+ Prvi:= TRUE;\r
+ FOR z:= 1 TO MaxBrojZemalja DO\r
+ IF z IN S THEN\r
+ IF Prvi THEN\r
+ WrStr(Ime[z]);\r
+ Prvi:= FALSE;\r
+ ELSE\r
+ WrStr(', ');\r
+ WrStr(Ime[z]);\r
+ END;\r
+ END;\r
+ END;\r
+ END StampajSkup;\r
+\r
+\r
+ PROCEDURE Stampa(RBr: LONGCARD; VAR Obojeno: BojeZemalja);\r
+ BEGIN\r
+ WrLn; WrLn; WrLngCard(RBr, 1);\r
+ WrLn; WrStr('Crvena: '); StampajSkup(Obojeno[Crvena]);\r
+ WrLn; WrStr('Plava: '); StampajSkup(Obojeno[Plava]);\r
+ WrLn; WrStr('Zelena: '); StampajSkup(Obojeno[Zelena]);\r
+ WrLn; WrStr('Zuta: '); StampajSkup(Obojeno[Zuta]);\r
+ END Stampa;\r
+\r
+ PROCEDURE Oboji(z: Zemlja);\r
+ VAR\r
+ i: Boja;\r
+ BEGIN\r
+ FOR i:= MIN(Boja) TO MAX(Boja) DO\r
+ IF Granice[z] * Obojeno[i] = SkupZ {} THEN\r
+ Obojeno[i]:= Obojeno[i] + SkupZ {z};\r
+ IF z = BrZ THEN\r
+ INC(RBr);\r
+ Stampa(RBr, Obojeno);\r
+ ELSE\r
+ Oboji(z + 1);\r
+ END;\r
+ Obojeno[i]:= Obojeno[i] - SkupZ {z};\r
+ END;\r
+ END;\r
+ END Oboji;\r
+\r
+BEGIN\r
+ Inicijalizacija;\r
+ Oboji(1);\r
+ (* Broj mogucih bojenja je 1 527 552 *)\r
+END Bojenje.\r
diff --git a/Cas08/Prezentacija.ppt b/Cas08/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..73a6b8b
Binary files /dev/null and b/Cas08/Prezentacija.ppt differ
index 0000000..73a6b8b
Binary files /dev/null and b/Cas08/Prezentacija.ppt differ
diff --git a/Cas09/Prezentacija.ppt b/Cas09/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..2c77cf5
Binary files /dev/null and b/Cas09/Prezentacija.ppt differ
index 0000000..2c77cf5
Binary files /dev/null and b/Cas09/Prezentacija.ppt differ
diff --git a/Cas09/Put.MOD b/Cas09/Put.MOD
--- /dev/null
+++ b/Cas09/Put.MOD
@@ -0,0 +1,143 @@
+MODULE Put;\r
+\r
+ FROM IO IMPORT\r
+ WrLn, WrStr, RdCard, WrCard, OK;\r
+\r
+ FROM Storage IMPORT\r
+ ALLOCATE;\r
+\r
+ CONST\r
+ MaxBrGrad = 50;\r
+\r
+ TYPE\r
+ Lista = POINTER TO Grad;\r
+ Grad = RECORD\r
+ Info: CARDINAL;\r
+ Veza: Lista;\r
+ END;\r
+ Mreza = ARRAY [1 .. MaxBrGrad] OF Lista;\r
+ Posecen = ARRAY [1 .. MaxBrGrad] OF BOOLEAN;\r
+\r
+ VAR\r
+ m: Mreza;\r
+ BrojGr: CARDINAL;\r
+ GPoc, GKra: CARDINAL;\r
+\r
+ PROCEDURE Ubaci(VAR L: Lista; G: CARDINAL);\r
+ VAR\r
+ Tek, Novi: Lista;\r
+ BEGIN\r
+ IF (L = NIL) OR (G < L^.Info) THEN\r
+ NEW(Novi);\r
+ Novi^.Info:= G;\r
+ Novi^.Veza:= L;\r
+ L:= Novi;\r
+ ELSE\r
+ Tek:= L;\r
+ WHILE (Tek^.Veza # NIL) AND (Tek^.Veza^.Info < G) DO\r
+ Tek:= Tek^.Veza;\r
+ END;\r
+ IF (Tek^.Veza = NIL) OR (Tek^.Veza^.Info > G) THEN\r
+ NEW(Novi);\r
+ Novi^.Info:= G;\r
+ Novi^.Veza:= Tek^.Veza;\r
+ Tek^.Veza:= Novi;\r
+ END;\r
+ END;\r
+ END Ubaci;\r
+\r
+ PROCEDURE Povezi(G1, G2: CARDINAL);\r
+ BEGIN\r
+ Ubaci(m[G1], G2);\r
+ Ubaci(m[G2], G1);\r
+ END Povezi;\r
+\r
+ PROCEDURE Unos(VAR G1, G2: CARDINAL);\r
+ VAR\r
+ G: CARDINAL;\r
+ BEGIN\r
+ REPEAT\r
+ WrStr('Unesite broj gradova (od 2 do ');\r
+ WrCard(MaxBrGrad, 1);\r
+ WrStr(') ---- ');\r
+ BrojGr:= RdCard();\r
+ WrLn;\r
+ UNTIL OK AND (2 <= BrojGr) AND (BrojGr <= MaxBrGrad);\r
+ FOR G:= 1 TO BrojGr DO\r
+ m[G]:= NIL;\r
+ END;\r
+ REPEAT\r
+ WrStr('Unesite dva grada koji su povezani linijom.');\r
+ REPEAT\r
+ WrLn;\r
+ WrStr('Unesite red. br. prvog grada (ili 0 za kraj unosa linija) -- ');\r
+ G1:= RdCard()\r
+ UNTIL OK AND (G1 <= BrojGr);\r
+ IF G1 > 0 THEN\r
+ REPEAT\r
+ WrStr('Unesite red. br. drugog grada ------------------------------ ');\r
+ G2:= RdCard();\r
+ UNTIL OK AND (1 <= G2) AND (G2 <= BrojGr) AND (G1 # G2);\r
+ Povezi(G1, G2);\r
+ END;\r
+ WrLn;\r
+ UNTIL G1 = 0;\r
+ REPEAT\r
+ WrLn;\r
+ WrLn;\r
+ WrStr('Unesite red. br. pocetnog grada -- ');\r
+ G1:= RdCard();\r
+ UNTIL OK AND (1 <= G1) AND (G1 <= BrojGr);\r
+ REPEAT\r
+ WrLn;\r
+ WrStr('Unesite red. br ciljnog grada -- ');\r
+ G2:= RdCard();\r
+ UNTIL OK AND (1 <= G2) AND (G2 <= BrojGr) AND (G1 # G2);\r
+ END Unos;\r
+\r
+ PROCEDURE NadjiPut(Od, Do, brojGr : CARDINAL);\r
+ VAR\r
+ Pos: Posecen;\r
+ Reseno: BOOLEAN;\r
+ i: CARDINAL;\r
+ Resenje: ARRAY [1 .. MaxBrGrad] OF CARDINAL;\r
+\r
+ PROCEDURE Pokusaj(Od, Br: CARDINAL; VAR Reseno: BOOLEAN);\r
+ VAR\r
+ Pok: Lista;\r
+ BEGIN\r
+ Pos[Od]:= TRUE;\r
+ Resenje[Br]:= Od;\r
+ IF Od = Do THEN\r
+ Reseno:= TRUE;\r
+ WrLn;\r
+ WrStr('Put koji treba precji je sledeci:');\r
+ WrLn;\r
+ FOR i:= 1 TO Br DO\r
+ WrCard(Resenje[i], 4);\r
+ END;\r
+ ELSE\r
+ Pok:= m[Od];\r
+ WHILE (Pok # NIL) AND NOT Reseno DO\r
+ WHILE (Pok # NIL) AND Pos[Pok^.Info] DO\r
+ Pok:= Pok^.Veza;\r
+ END;\r
+ IF Pok # NIL THEN\r
+ Pokusaj(Pok^.Info, Br + 1, Reseno);\r
+ END;\r
+ END;\r
+ END;\r
+ END Pokusaj;\r
+\r
+ BEGIN\r
+ Reseno:= FALSE;\r
+ FOR i:= 1 TO BrojGr DO\r
+ Pos[i]:= FALSE;\r
+ END;\r
+ Pokusaj(Od, 1, Reseno);\r
+ END NadjiPut;\r
+\r
+BEGIN\r
+ Unos(GPoc, GKra);\r
+ NadjiPut(GPoc, GKra, BrojGr);\r
+END Put.\r
diff --git a/Cas10/PERMP.MOD b/Cas10/PERMP.MOD
--- /dev/null
+++ b/Cas10/PERMP.MOD
@@ -0,0 +1,92 @@
+MODULE PermP;\r
+\r
+FROM IO IMPORT\r
+ WrStr, WrLn, WrCard, RdCard, WrChar, RdKey, OK;\r
+\r
+CONST\r
+ MaxDim = 50;\r
+\r
+TYPE\r
+ Niz = ARRAY [1 .. MaxDim] OF CHAR;\r
+\r
+VAR\r
+ A: Niz;\r
+ n: CARDINAL;\r
+\r
+PROCEDURE Unos(VAR n: CARDINAL; VAR A: Niz);\r
+VAR\r
+ i: CARDINAL;\r
+BEGIN\r
+ REPEAT\r
+ WrStr('Unesite n (1 <= n <= ');\r
+ WrCard(MaxDim, 1);\r
+ WrStr(') --- ');\r
+ n:= RdCard();\r
+ WrLn;\r
+ UNTIL OK AND (1 <= n) AND (n <= MaxDim);\r
+ REPEAT\r
+ WrLn;\r
+ WrStr('Unesite ');\r
+ WrCard(n, 1);\r
+ WrStr(' slova koja treba permutovati (mogu se i ponavljati):');\r
+ WrLn;\r
+ WrLn;\r
+ i:= 0;\r
+ REPEAT\r
+ INC(i);\r
+ A[i]:= RdKey();\r
+ WrChar(A[i])\r
+ UNTIL (i = n) OR ((CAP(A[i]) < 'A') AND (CAP(A[i]) > 'Z')\r
+ AND (A[i] < '0') AND (A[i] > '9'));\r
+ UNTIL NOT ((CAP(A[i]) < 'A') AND (CAP(A[i]) > 'Z') AND\r
+ (A[i] < '0') AND (A[i] > '9'));\r
+END Unos;\r
+\r
+PROCEDURE Permutacije(n: CARDINAL; VAR A: Niz);\r
+\r
+ PROCEDURE Nadji(k: CARDINAL);\r
+ VAR\r
+ i, j: CARDINAL;\r
+ Temp: CHAR;\r
+ BEGIN\r
+ IF k = 1 THEN\r
+ FOR i:= 1 TO n DO\r
+ WrChar(A[i]);\r
+ END;\r
+ WrLn;\r
+ ELSE\r
+ Nadji(k - 1);\r
+ FOR i:= 1 TO k - 1 DO\r
+ IF A[k] # A[i] THEN\r
+ (* Zamenimo elemente samo ako su razliciti *)\r
+ j:= 1;\r
+ WHILE (j < i) AND (A[j] # A[i]) DO\r
+ INC(j);\r
+ END;\r
+ IF j = i THEN\r
+ (* A[i] nema duplikata u skupu {a[1], ... , a[i-1] *)\r
+ Temp:= A[i];\r
+ A[i]:= A[k];\r
+ A[k]:= Temp;\r
+ Nadji(k - 1);\r
+ Temp:= A[i];\r
+ A[i]:= A[k];\r
+ A[k]:= Temp;\r
+ END;\r
+ END;\r
+ END;\r
+ END;\r
+ END Nadji;\r
+\r
+BEGIN\r
+ Nadji(n);\r
+END Permutacije;\r
+\r
+BEGIN \r
+ Unos(n, A);\r
+ WrLn;\r
+ WrLn;\r
+ WrStr('Permutacije: ');\r
+ WrLn;\r
+ Permutacije(n, A);\r
+END PermP.\r
diff --git a/Cas10/Prezentacija.ppt b/Cas10/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..7097444
Binary files /dev/null and b/Cas10/Prezentacija.ppt differ
index 0000000..7097444
Binary files /dev/null and b/Cas10/Prezentacija.ppt differ
diff --git a/Cas11/Prezentacija.ppt b/Cas11/Prezentacija.ppt
new file mode 100644 (file)
index 0000000..e3b4ce5
Binary files /dev/null and b/Cas11/Prezentacija.ppt differ
index 0000000..e3b4ce5
Binary files /dev/null and b/Cas11/Prezentacija.ppt differ
diff --git a/Cas11/QUEENS.MOD b/Cas11/QUEENS.MOD
--- /dev/null
+++ b/Cas11/QUEENS.MOD
@@ -0,0 +1,315 @@
+MODULE Queens;\r
+\r
+ FROM IO IMPORT\r
+ WrStr, WrLn, WrCard, RdCard, OK;\r
+\r
+ FROM SYSTEM IMPORT\r
+ TSIZE;\r
+\r
+ FROM Storage IMPORT\r
+ ALLOCATE, DEALLOCATE;\r
+\r
+ IMPORT FIO;\r
+\r
+ CONST\r
+ MaxDim = 50;\r
+\r
+ TYPE\r
+ Indeks = [1 .. MaxDim];\r
+ DomenCene = [0 .. MaxDim * MaxDim];\r
+ DomenBrojaKraljica = [1 .. MaxDim * MaxDim];\r
+\r
+ PPolozaj = POINTER TO SPolozaj;\r
+ SPolozaj = RECORD\r
+ Ko, Vr: Indeks;\r
+ Cena: DomenCene;\r
+ Veza: PPolozaj;\r
+ END;\r
+\r
+ PKraljica = POINTER TO SKraljica;\r
+ SKraljica = RECORD\r
+ Pre, Sled: PKraljica;\r
+ Kandidati: PPolozaj;\r
+ TekKo, TekVr: Indeks;\r
+ END;\r
+\r
+ StanjeTip = RECORD\r
+ Cena: DomenCene;\r
+ PrvaKra, TekKra: PKraljica;\r
+ END;\r
+ StatusTip = (stZauzeto, stNapadnuto, stSlobodno);\r
+ ResenjeTip = RECORD\r
+ Cena: DomenCene;\r
+ Poz: ARRAY Indeks, Indeks OF StatusTip;\r
+ END;\r
+ VAR\r
+ BrojKol, BrojVrs: Indeks;\r
+ BrojKraljica: DomenBrojaKraljica;\r
+\r
+ PROCEDURE Unos();\r
+ BEGIN\r
+ REPEAT\r
+ WrLn;\r
+ WrStr('Unesite broj Kolona sahovske table (od 1 do ');\r
+ WrCard(MaxDim, 1);\r
+ WrStr(') ------- ');\r
+ BrojKol:= RdCard();\r
+ UNTIL OK AND (1 <= BrojKol) AND (BrojKol <= MaxDim);\r
+ REPEAT\r
+ WrLn;\r
+ WrStr('Unesite broj Vrsta sahovske table (od 1 do ');\r
+ WrCard(MaxDim, 1);\r
+ WrStr(') ------- ');\r
+ BrojVrs:= RdCard();\r
+ UNTIL OK AND (1 <= BrojVrs) AND (BrojVrs <= MaxDim);\r
+ REPEAT\r
+ WrLn;\r
+ WrStr('Unesite broj kraljica (od 1 do ');\r
+ WrCard(BrojKol * BrojVrs, 1);\r
+ WrStr(') ------- ');\r
+ BrojKraljica:= RdCard();\r
+ UNTIL OK AND (1 <= BrojKraljica) AND (BrojKraljica <= BrojKol * BrojVrs);\r
+ END Unos;\r
+\r
+ PROCEDURE Postavi(VAR Stanje: StanjeTip);\r
+ VAR\r
+ Temp: PPolozaj;\r
+ BEGIN\r
+ WITH Stanje DO\r
+ Temp:= TekKra^.Kandidati;\r
+ TekKra^.Kandidati:= Temp^.Veza;\r
+ TekKra^.TekKo:= Temp^.Ko;\r
+ TekKra^.TekVr:= Temp^.Vr;\r
+ Cena:= Temp^.Cena;\r
+ DISPOSE(Temp);\r
+ END;\r
+ END Postavi;\r
+\r
+ PROCEDURE Inicijalizacija(VAR Stanje: StanjeTip; VAR Br: CARDINAL);\r
+ VAR\r
+ Tek, Pom: PKraljica;\r
+ i: DomenBrojaKraljica;\r
+ BEGIN\r
+ Br:= 0;\r
+ WITH Stanje DO\r
+ Cena:= 0;\r
+ NEW(PrvaKra);\r
+ TekKra:= PrvaKra;\r
+ Tek:= PrvaKra;\r
+ Tek^.Pre:= NIL;\r
+ FOR i:= 2 TO BrojKraljica DO\r
+ Pom:= Tek;\r
+ NEW(Tek^.Sled);\r
+ Tek:= Tek^.Sled;\r
+ Tek^.Pre:= Pom;\r
+ END;\r
+ Tek^.Sled:= NIL;\r
+ END;\r
+ END Inicijalizacija;\r
+\r
+ PROCEDURE Ispitaj(Ko, Vr: Indeks; Granica: PKraljica; VAR Stanje: StanjeTip; VAR Status: StatusTip);\r
+ VAR\r
+ Tek: PKraljica;\r
+ Jos: BOOLEAN;\r
+ BEGIN\r
+ WITH Stanje DO\r
+ Tek:= PrvaKra;\r
+ Jos:= Tek # Granica;\r
+ Status:= stSlobodno;\r
+ WHILE Jos DO\r
+ IF (Tek^.TekKo = Ko) AND (Tek^.TekVr = Vr) THEN\r
+ Status:= stZauzeto;\r
+ Jos:= FALSE;\r
+ ELSE\r
+ IF (Tek^.TekKo = Ko) OR (Tek^.TekVr = Vr) OR (ABS(Tek^.TekKo - Ko) = ABS(Tek^.TekVr - Vr)) THEN\r
+ Status:= stNapadnuto;\r
+ END;\r
+ IF Tek^.Sled= Granica THEN\r
+ Jos:= FALSE;\r
+ ELSE\r
+ Tek:= Tek^.Sled;\r
+ END;\r
+ END;\r
+ END;\r
+ END;\r
+ END Ispitaj;\r
+\r
+ PROCEDURE Stampa(VAR Resenje: ResenjeTip);\r
+ CONST\r
+ ImeFajla = "Resenje.txt";\r
+ VAR\r
+ Ko, Vr: Indeks;\r
+ Izlaz: FIO.File;\r
+ BEGIN\r
+ IF FIO.Exists(ImeFajla) THEN\r
+ Izlaz:= FIO.Append(ImeFajla);\r
+ ELSE\r
+ Izlaz:= FIO.Create(ImeFajla);\r
+ END;\r
+ WrLn;\r
+ WrStr('-----------------------------------------------------------------');\r
+ WrStr('---------------');\r
+ WrLn;\r
+ FIO.WrLn(Izlaz);\r
+ WrStr('Kraljice treba staviti na sledeca polja:');\r
+ FIO.WrStr(Izlaz, 'Kraljice treba staviti na sledeca polja:');\r
+ WrLn;\r
+ FIO.WrLn(Izlaz);\r
+ FOR Vr:= BrojVrs TO 1 BY -1 DO\r
+ WrLn;\r
+ FIO.WrLn(Izlaz);\r
+ FOR Ko:= 1 TO BrojKol DO\r
+ CASE Resenje.Poz[Ko, Vr] OF\r
+ stZauzeto: WrStr(' Q');\r
+ FIO.WrStr(Izlaz, ' Q'); |\r
+ stNapadnuto: WrStr(' x');\r
+ FIO.WrStr(Izlaz, ' x');\r
+ ELSE\r
+ WrStr(' .');\r
+ FIO.WrStr(Izlaz, ' .');\r
+ END;\r
+ END;\r
+ END;\r
+ WrLn;\r
+ FIO.WrLn(Izlaz);\r
+ WrLn;\r
+ FIO.WrLn(Izlaz);\r
+ WrStr('Broj slobodnih polja je: ');\r
+ FIO.WrStr(Izlaz, 'Broj slobodnih polja je: ');\r
+ WrCard(BrojKol * BrojVrs - Resenje.Cena, 1);\r
+ FIO.WrCard(Izlaz, BrojKol * BrojVrs - Resenje.Cena, 1);\r
+ FIO.Close(Izlaz);\r
+ END Stampa;\r
+\r
+ PROCEDURE Dame(BrojKol, BrojVrs: Indeks; BrojKraljica: DomenBrojaKraljica);\r
+ VAR\r
+ Stanje: StanjeTip;\r
+ Resenje: ResenjeTip;\r
+ MinCena: DomenCene;\r
+ Br: CARDINAL;\r
+\r
+ PROCEDURE NadjiKandidate(VAR Stanje: StanjeTip);\r
+\r
+ PROCEDURE NadjiCenu(k, v: Indeks; VAR Cena: DomenCene; VAR Stanje: StanjeTip);\r
+ VAR\r
+ Ko, Vr: Indeks;\r
+ Status: StatusTip;\r
+ BEGIN\r
+ Cena:= 0;\r
+ FOR Ko:= 1 TO BrojKol DO\r
+ FOR Vr:= 1 TO BrojVrs DO\r
+ IF (Ko # k) AND (Vr # v) AND (ABS(Ko - k) # ABS(Vr - v)) THEN\r
+ Ispitaj(Ko, Vr, Stanje.TekKra, Stanje, Status);\r
+ IF Status # stSlobodno THEN\r
+ INC(Cena);\r
+ END;\r
+ ELSE\r
+ INC(Cena);\r
+ END;\r
+ END;\r
+ END;\r
+ END NadjiCenu;\r
+\r
+ PROCEDURE Ubaci(VAR Prvi, Novi: PPolozaj);\r
+ VAR\r
+ Tek: PPolozaj;\r
+ BEGIN\r
+ IF (Prvi = NIL) OR (Novi^.Cena < Prvi^.Cena) THEN\r
+ Novi^.Veza:= Prvi;\r
+ Prvi:= Novi;\r
+ ELSE\r
+ Tek:= Prvi;\r
+ WHILE (Tek^.Veza # NIL) AND (Tek^.Veza^.Cena < Novi^.Cena) DO\r
+ Tek:= Tek^.Veza;\r
+ END;\r
+ Novi^.Veza:= Tek^.Veza;\r
+ Tek^.Veza:= Novi;\r
+ END;\r
+ END Ubaci;\r
+\r
+ VAR\r
+ k, v: Indeks;\r
+ Temp, Prvi: PPolozaj;\r
+ NovaCena: DomenCene;\r
+ Status: StatusTip;\r
+ PocKol, PocVrs: CARDINAL;\r
+\r
+ BEGIN\r
+ Prvi:= NIL;\r
+ IF Stanje.TekKra = Stanje.PrvaKra THEN\r
+ PocKol:= 1;\r
+ ELSE\r
+ PocKol:= Stanje.TekKra^.Pre^.TekKo;\r
+ END;\r
+ FOR k:= PocKol TO BrojKol DO\r
+ IF (k = PocKol) AND (Stanje.TekKra # Stanje.PrvaKra) THEN\r
+ PocVrs:= Stanje.TekKra^.Pre^.TekVr + 1;\r
+ ELSE\r
+ PocVrs:= 1;\r
+ END;\r
+ FOR v:= PocVrs TO BrojVrs DO\r
+ NadjiCenu(k, v, NovaCena, Stanje);\r
+ IF NovaCena < MinCena THEN\r
+ NEW(Temp);\r
+ WITH Temp^ DO\r
+ Veza:= NIL;\r
+ Ko:= k;\r
+ Vr:= v;\r
+ Cena:= NovaCena;\r
+ END;\r
+ Ubaci(Prvi, Temp);\r
+ END;\r
+ END;\r
+ END;\r
+ Stanje.TekKra^.Kandidati:= Prvi;\r
+ END NadjiKandidate;\r
+\r
+ PROCEDURE ZapamtiResenje(VAR Stanje: StanjeTip; VAR Resenje: ResenjeTip);\r
+ VAR\r
+ Ko, Vr: Indeks;\r
+ Status: StatusTip;\r
+ BEGIN\r
+ Resenje.Cena:= Stanje.Cena;\r
+ FOR Ko:= 1 TO BrojKol DO\r
+ FOR Vr:= 1 TO BrojVrs DO\r
+ Ispitaj(Ko, Vr, NIL, Stanje, Status);\r
+ Resenje.Poz[Ko, Vr]:= Status;\r
+ END;\r
+ END;\r
+ END ZapamtiResenje;\r
+\r
+ BEGIN\r
+ Inicijalizacija(Stanje, Br);\r
+ MinCena:= BrojKol * BrojVrs + 1;\r
+ NadjiKandidate(Stanje);\r
+ WITH Stanje DO\r
+ WHILE TekKra # NIL DO\r
+ WHILE TekKra^.Kandidati # NIL DO\r
+ IF TekKra = PrvaKra THEN\r
+ INC(Br);\r
+ WrCard(Br, 4);\r
+ END;\r
+ Postavi(Stanje);\r
+ IF TekKra^.Sled = NIL THEN\r
+ IF Cena < MinCena THEN\r
+ MinCena:= Cena;\r
+ ZapamtiResenje(Stanje, Resenje);\r
+ END;\r
+ ELSE\r
+ TekKra:= TekKra^.Sled;\r
+ NadjiKandidate(Stanje);\r
+ END;\r
+ END;\r
+ TekKra:= TekKra^.Pre;\r
+ END;\r
+ Stampa(Resenje);\r
+ END;\r
+ END Dame;\r
+\r
+BEGIN\r
+ Unos();\r
+ WrLn;\r
+ WrStr('Sacekajte !!!');\r
+ WrLn;\r
+ Dame(BrojKol, BrojVrs, BrojKraljica);\r
+END Queens.\r
diff --git a/Cas11/RESENJE.TXT b/Cas11/RESENJE.TXT
--- /dev/null
+++ b/Cas11/RESENJE.TXT
@@ -0,0 +1,8 @@
+\r
+Kraljice treba staviti na sledeca polja:\r
+\r
+ Q Q x\r
+ x Q x\r
+ x x .\r
+\r
+Broj slobodnih polja je: 1
\ No newline at end of file