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: 9d18240)
raw | patch | inline | side by side (parent: 9d18240)
author | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 24 Oct 2015 13:02:58 +0000 (15:02 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 24 Oct 2015 13:02:58 +0000 (15:02 +0200) |
- tekst zadatka
- primeri fajlova
- resenje zadatka
- primeri fajlova
- resenje zadatka
sortiranje/knjige/Biblioteka.java | [new file with mode: 0644] | patch | blob |
sortiranje/knjige/knjige12.txt | [new file with mode: 0644] | patch | blob |
sortiranje/knjige/knjige146.txt | [new file with mode: 0644] | patch | blob |
sortiranje/knjige/zad-sort1.txt | [new file with mode: 0644] | patch | blob |
diff --git a/sortiranje/knjige/Biblioteka.java b/sortiranje/knjige/Biblioteka.java
--- /dev/null
@@ -0,0 +1,155 @@
+/**
+ * Resenje zadatka sort1 sa vezbi
+ */
+import java.util.Arrays;
+
+import org.svetovid.io.SvetovidReader;
+import org.svetovid.io.SvetovidWriter;
+
+// Klasa koja opisuje jednu knjigu
+class Knjiga implements Comparable<Knjiga> {
+
+ private final int id;
+ private final String naslov;
+ private final String autor;
+
+ public Knjiga(int id, String naslov, String autor) {
+ this.id = id;
+ this.naslov = naslov;
+ this.autor = autor;
+ }
+
+ public String toString() {
+ return id + " " + autor + ": " + naslov;
+ }
+
+ public int compareTo(Knjiga that) {
+ // najjednostavnija verzija: knjige uredjene po "id" broju
+ //return this.id - that.id;
+
+ // autor-naslov
+ int rez = this.autor.compareTo(that.autor);
+ if (rez == 0) {
+ rez = this.naslov.compareTo(that.naslov);
+ }
+ return rez;
+ }
+
+ public String getNaslov(){
+ return naslov;
+ }
+
+ public String getAutor() {
+ return autor;
+ }
+
+ public int getId() {
+ return id;
+ }
+}
+
+// Glavni program
+public class Biblioteka {
+
+ public static void main(String[] arguments) {
+
+ // Ucitavanje knjiga iz fajla
+ String fajl = Svetovid.in.readLine("Unesite ime fajla sa knjigama:");
+ Knjiga[] niz = ucitajKnjige(fajl);
+
+ if (niz != null) {
+ // Stampanje ucitanog niza
+ Svetovid.out.println();
+ Svetovid.out.println("Nesortirani niz:");
+ Svetovid.out.println();
+ stampajNiz(niz);
+
+ // Sortiranje niza
+ Arrays.sort(niz);
+
+ // Stampanje sortiranog niza
+ Svetovid.out.println();
+ Svetovid.out.println("Sortirani niz:");
+ Svetovid.out.println();
+ stampajNiz(niz);
+
+ // Ispis knjiga u fajl
+ String izlazni = Svetovid.in.readLine("Unesite ime fajla za ispis:");
+ snimiKnjige(niz,izlazni);
+
+ } else {
+ System.err.println("Greska pri ucitavanju niza, kraj rada");
+ }
+
+ }
+
+ public static Knjiga[] ucitajKnjige(String fajl) {
+
+ // Ako ne mozemo da otvorimo fajl, ne ucitavamo knjige
+ if (!Svetovid.testIn(fajl)) {
+ return null;
+ }
+
+ // Ako mozemo, napravimo precicu 'in' da ne bi morali da
+ // svaki put kuvamo 'Svetovid.in(fajl)'
+ SvetovidReader in = Svetovid.in(fajl);
+
+ // Koliko ima knjiga u fajlu?
+ int br = Svetovid.in(fajl).readInt();
+
+ // Napravimo niz odgovarajuce velicine
+ Knjiga[] rez = new Knjiga[br];
+
+ // Ucitamo knjige
+ for (int i = 0; i < br; i++) {
+
+ // Ucitamo podatke o knjizi
+ int id = in.readInt();
+ String naslov = in.readLine();
+ String autor = in.readLine();
+
+ // Napravimo knjigu
+ Knjiga knjiga = new Knjiga(id, naslov, autor);
+
+ // Dodamo knjigu u niz
+ rez[i] = knjiga;
+
+ }
+
+ // Vratimo ucitani niz
+ return rez;
+
+ }
+
+ public static void stampajNiz(Knjiga[] niz) {
+ for (Knjiga knjiga : niz) {
+ System.out.println(knjiga);
+ }
+ }
+
+ public static void snimiKnjige(Knjiga[] niz, String ime) {
+ if (!Svetovid.testOut(ime)) {
+ // ne mozemo da snimimo, vracamo se
+ System.err.println("Nemoguce snimanje u fajl");
+ return;
+ }
+
+ // napravimo precicu 'out' da ne bi morali da
+ // svaki put pisemo 'Svetovid.out(ime)'
+ SvetovidWriter out = Svetovid.out(ime);
+
+ // pisemo broj knjiga, kao u originalu
+ out.println(niz.length);
+
+ // za svaku knjigu ispisujemo podatke
+ for (Knjiga knjiga : niz) {
+ out.println(knjiga.getId());
+ out.println(knjiga.getNaslov());
+ out.println(knjiga.getAutor());
+ }
+
+ // zatvorimo izlaz
+ out.close();
+
+ }
+}
diff --git a/sortiranje/knjige/knjige12.txt b/sortiranje/knjige/knjige12.txt
--- /dev/null
@@ -0,0 +1,37 @@
+12\r
+202\r
+A Clash of Kings\r
+George R.R. Martin\r
+211\r
+The Gunslinger\r
+Stephen King\r
+214\r
+Wizard and Glass\r
+Stephen King\r
+201\r
+A Game of Thrones\r
+George R.R. Martin\r
+205\r
+A Dance with Dragons\r
+George R.R. Martin\r
+212\r
+The Drawing of the Three\r
+Stephen King\r
+213\r
+The Waste Lands\r
+Stephen King\r
+217\r
+The Dark Tower\r
+Stephen King\r
+203\r
+A Storm of Swords\r
+George R.R. Martin\r
+215\r
+Wolves of the Calla\r
+Stephen King\r
+204\r
+A Feast for Crows\r
+George R.R. Martin\r
+216\r
+Song of Susannah\r
+Stephen King
\ No newline at end of file
diff --git a/sortiranje/knjige/knjige146.txt b/sortiranje/knjige/knjige146.txt
--- /dev/null
@@ -0,0 +1,439 @@
+146\r
+13\r
+All Passion Spent\r
+Vita Sackville-West\r
+38\r
+A Darkling Plain\r
+Philip Reeve\r
+65\r
+Nectar in a Sieve\r
+Kamala Markandaya\r
+125\r
+Terrible Swift Sword\r
+Bruce Catton\r
+11\r
+Of Human Bondage\r
+W. Somerset Maugham\r
+131\r
+The Other Side of Silence\r
+Andre Brink\r
+15\r
+Look Homeward, Angel\r
+Thomas Wolfe\r
+81\r
+Consider Phlebas\r
+Iain M. Banks\r
+37\r
+If Not Now, When?\r
+Primo Levi\r
+85\r
+Quo Vadis\r
+Henryk Sienkiewicz\r
+109\r
+The House of Mirth\r
+Edith Wharton\r
+39\r
+His Dark Materials\r
+Philip Pullman\r
+66\r
+Noli Me Tangere\r
+Jos Rizal\r
+68\r
+East of Eden\r
+John Steinbeck\r
+117\r
+Brandy of the Damned\r
+Colin Wilson\r
+92\r
+Oh! To be in England\r
+H. E. Bates\r
+35\r
+The Golden Apples of the Sun\r
+Ray Bradbury\r
+12\r
+The Painted Veil\r
+W. Somerset Maugham\r
+58\r
+The Green Bay Tree\r
+Louis Bromfield\r
+97\r
+Arms and the Man\r
+George Bernard Shaw\r
+108\r
+A Fanatic Heart\r
+Edna O'Brien\r
+115\r
+No Country for Old Men\r
+Cormac McCarthy\r
+18\r
+The Wives of Bath\r
+Susan Swan\r
+25\r
+Tiger! Tiger!\r
+Rudyard Kipling short story\r
+106\r
+For Whom the Bell Tolls\r
+Ernest Hemingway\r
+114\r
+Down to a Sunless Sea\r
+David Graham\r
+136\r
+The Doors of Perception\r
+Aldous Huxley\r
+30\r
+I Will Fear No Evil\r
+Robert A. Heinlein\r
+82\r
+Look to Windward\r
+Iain M. Banks\r
+32\r
+To Sail Beyond the Sunset\r
+Robert A. Heinlein\r
+104\r
+Vile Bodies\r
+Evelyn Waugh\r
+112\r
+Clouds of Witness\r
+Dorothy L. Sayers\r
+21\r
+The Stars' Tennis Balls\r
+Stephen Fry\r
+53\r
+The Curious Incident of the Dog in the Night-time\r
+Mark Haddon\r
+130\r
+An Instant In The Wind\r
+Andre Brink\r
+142\r
+Endless Night\r
+Agatha Christie\r
+121\r
+The Cricket on the Hearth\r
+Charles Dickens\r
+143\r
+The Mirror Crack'd from Side to Side\r
+Agatha Christie\r
+45\r
+Blithe Spirit\r
+Noel Coward\r
+20\r
+Moab Is My Washpot\r
+Stephen Fry\r
+63\r
+Mother Night\r
+Kurt Vonnegut\r
+34\r
+Recalled to Life\r
+Reginald Hill\r
+44\r
+Cabbages and Kings\r
+O. Henry\r
+101\r
+Tender Is the Night\r
+F. Scott Fitzgerald\r
+102\r
+This Side of Paradise\r
+F. Scott Fitzgerald\r
+94\r
+The Yellow Meads of Asphodel\r
+H. E. Bates\r
+27\r
+Recalled to Life\r
+Robert Silverberg\r
+78\r
+Let Us Now Praise Famous Men\r
+James Agee\r
+33\r
+Some Buried Caesar\r
+Rex Stout\r
+140\r
+The Line of Beauty\r
+Alan Hollinghurst\r
+128\r
+The Soldier's Art\r
+Anthony Powell\r
+77\r
+Mr Standfast\r
+John Buchan\r
+17\r
+The Waste Land\r
+T. S. Eliot\r
+129\r
+What's Become of Waring\r
+Anthony Powell\r
+24\r
+The Way of All Flesh\r
+Samuel Butler\r
+26\r
+For a Breath I Tarry\r
+Roger Zelazny\r
+71\r
+Of Mice and Men\r
+John Steinbeck\r
+7\r
+Ego Dominus Tuus\r
+William Butler Yeats\r
+124\r
+Surprised by Joy\r
+C. S. Lewis\r
+10\r
+The Alien Corn (short story)\r
+W. Somerset Maugham\r
+95\r
+Dying of the Light\r
+George R. R. Martin\r
+87\r
+A Many-Splendoured Thing\r
+Han Suyin\r
+29\r
+The Monkey's Raincoat\r
+Robert Crais\r
+3\r
+As I Lay Dying\r
+William Faulkner\r
+69\r
+The Grapes of Wrath\r
+John Steinbeck\r
+4\r
+If I Forget Thee Jerusalem\r
+William Faulkner\r
+70\r
+In Dubious Battle\r
+John Steinbeck\r
+46\r
+No Highway\r
+Nevil Shute\r
+52\r
+The World, the Flesh and the Devil\r
+Mary Elizabeth Braddon\r
+83\r
+Consider the Lilies\r
+Iain Crichton Smith\r
+72\r
+To a God Unknown\r
+John Steinbeck\r
+119\r
+No Longer at Ease\r
+Chinua Achebe\r
+2\r
+Absalom, Absalom!\r
+William Faulkner\r
+90\r
+How Sleep the Brave\r
+H. E. Bates\r
+137\r
+Eyeless in Gaza\r
+Aldous Huxley\r
+141\r
+Butter In a Lordly Dish\r
+Agatha Christie\r
+6\r
+Lilies of the Field\r
+William Edmund Barrett\r
+113\r
+O Jerusalem!\r
+Dominique Lapierre and Larry Collins\r
+42\r
+Cover Her Face\r
+P. D. James\r
+103\r
+A Handful of Dust\r
+Evelyn Waugh\r
+55\r
+The Moon by Night\r
+Madeleine L'Engle\r
+99\r
+Bonjour Tristesse\r
+Fransoise Sagan\r
+73\r
+A Confederacy of Dunces\r
+John Kennedy Toole\r
+67\r
+Everything is Illuminated\r
+Jonathan Safran Foer\r
+60\r
+The Little Foxes\r
+Lillian Hellman\r
+122\r
+The Heart Is a Lonely Hunter\r
+Carson McCullers\r
+105\r
+Ah, Wilderness!\r
+Eugene O'Neill\r
+19\r
+Time of our Darkness\r
+Stephen Gray\r
+43\r
+The Skull Beneath the Skin\r
+P. D. James\r
+61\r
+Time To Murder And Create\r
+Lawrence Block\r
+59\r
+Number the Stars\r
+Lois Lowry\r
+47\r
+Alone on a Wide, Wide Sea\r
+Michael Morpurgo\r
+9\r
+Dulce et Decorum Est\r
+Wilfred Owen\r
+74\r
+Death Be Not Proud\r
+John Gunther\r
+145\r
+Postern of Fate\r
+Agatha Christie\r
+139\r
+Those Barren Leaves\r
+Aldous Huxley\r
+89\r
+Fair Stood the Wind for France\r
+H. E. Bates\r
+62\r
+A Monstrous Regiment of Women\r
+Laurie R. King\r
+36\r
+I Sing the Body Electric\r
+Ray Bradbury\r
+118\r
+The Way Through the Woods\r
+Colin Dexter\r
+132\r
+Tiger! Tiger! - alternative title of The Stars My Destination\r
+Alfred Bester\r
+5\r
+Shall not Perish\r
+William Faulkner\r
+56\r
+A Swiftly Tilting Planet\r
+Madeleine L'Engle\r
+93\r
+When the Green Woods Laugh\r
+H. E. Bates\r
+98\r
+Ring of Bright Water\r
+Gavin Maxwell\r
+100\r
+The Violent Bear It Away\r
+Flannery O'Connor\r
+49\r
+Specimen Days\r
+Michael Cunningham\r
+96\r
+Such, Such Were the Joys\r
+George Orwell\r
+120\r
+Things Fall Apart\r
+Chinua Achebe\r
+14\r
+The Lathe of Heaven\r
+Ursula K. Le Guin\r
+40\r
+In a Dry Season\r
+Peter Robinson\r
+8\r
+O Pioneers!\r
+Willa Cather\r
+107\r
+The Sun Also Rises\r
+Ernest Hemingway\r
+48\r
+Behold the Man\r
+Michael Moorcock\r
+144\r
+The Moving Finger\r
+Agatha Christie\r
+79\r
+Waiting for the Barbarians\r
+J.M. Coetzee\r
+88\r
+The Daffodil Sky\r
+H. E. Bates\r
+75\r
+A Time to Kill\r
+John Grisham\r
+28\r
+All the King's Men\r
+Robert Penn Warren\r
+54\r
+Gone with the Wind\r
+Margaret Mitchell\r
+80\r
+The Proper Study\r
+Isaac Asimov\r
+135\r
+Beyond the Mexique Bay\r
+Aldous Huxley\r
+146\r
+The Wealth of Nations\r
+Adam Smith\r
+91\r
+Now Sleeps the Crimson Petal\r
+H. E. Bates\r
+51\r
+Precious Bane\r
+Mary Webb\r
+64\r
+The Far-Distant Oxus\r
+Katharine Hull and Pamela Whitlock\r
+111\r
+Where Angels Fear to Tread\r
+E. M. Forster\r
+57\r
+The Road Less Traveled\r
+M. Scott Peck\r
+1\r
+Vanity Fair\r
+William Makepeace Thackeray\r
+16\r
+Far From the Madding Crowd\r
+Thomas Hardy\r
+41\r
+The Parliament of Man\r
+Paul Kennedy\r
+23\r
+Alien Corn (play)\r
+Sidney Howard\r
+110\r
+A Passage to India\r
+E. M. Forster\r
+133\r
+After Many a Summer Dies the Swan\r
+Aldous Huxley\r
+123\r
+A che punto a la notte\r
+Carlo Fruttero and Franco Lucentini\r
+126\r
+An Evil Cradling\r
+Brian Keenan\r
+50\r
+I Know Why the Caged Bird Sings\r
+Maya Angelou\r
+134\r
+Antic Hay\r
+Aldous Huxley\r
+22\r
+Fear and Trembling\r
+Soren Kierkegaard\r
+116\r
+To Say Nothing of the Dog\r
+Connie Willis\r
+76\r
+Great Work of Time\r
+John Crowley\r
+127\r
+A Glass of Blessings\r
+Barbara Pym\r
+84\r
+Fame Is the Spur\r
+Howard Spring\r
+86\r
+The Golden Bowl\r
+Henry James\r
+138\r
+Jesting Pilate\r
+Aldous Huxley\r
+31\r
+Stranger in a Strange Land\r
+Robert A. Heinlein\r
diff --git a/sortiranje/knjige/zad-sort1.txt b/sortiranje/knjige/zad-sort1.txt
--- /dev/null
@@ -0,0 +1,63 @@
+************************************************************\r
+ Zadatak za vežbu - sortiranje 1\r
+************************************************************\r
+\r
+Napisati program koji ucitava niz knjiga iz fajla, sortira\r
+ih i ispisuje u drugi fajl. Imena fajlova zadaje korisnik.\r
+\r
+\r
+Format fajla\r
+------------\r
+\r
+Fajl je formatiran na sledeci nacin:\r
+\r
+U prvom redu stoji broj N.\r
+\r
+Posle njega sledi opis N elemenata niza.\r
+\r
+Svaki element je predstavljen u tri reda. U prvom redu se\r
+nalazi Id knjige, tipa `int`, u sledecem je ime knjige, a\r
+u trecem ime pisca. Imena su stringovi.\r
+\r
+ Id\r
+ Naslov\r
+ Pisac\r
+\r
+Dati su fajlovi knjige12.txt i knjige146.txt sa po 12 i 146\r
+knjiga u njima, respektivno, na kojima se moze testirati \r
+program.\r
+\r
+Predpostaviti ako fajl postoji da je ispravan, odnosno da\r
+je u tacno opisanom formatu.\r
+\r
+\r
+O sortiranju\r
+------------\r
+\r
+Za sortiranje koristiti metod `sort` iz klase `Arrays` iz\r
+paketa `java.util`.\r
+\r
+Klasa koja predstavlja knjigu treba da implementira interfejs\r
+`Comparable` i da ima svoj `compareTo` metod da bi niz\r
+mogao biti sortiran gore pomenutim metodom. Na primer\r
+\r
+ class Knjiga implements Comparable<Knjiga> {\r
+ ...\r
+ public int compareTo(Knjiga druga) {\r
+ ....\r
+ }\r
+ ...\r
+ }\r
+\r
+\r
+Najjednostavnija varijanta je da se niz knjiga sortira po id-u\r
+knjige.\r
+\r
+Kada se testira da to radi, prepraviti da se knjige sortiraju\r
+po piscu i po naslovu, odnosno kod njiga kod kojih je pisac isti\r
+knjige treba da su sortirane po naslovu.\r
+\r
+Sortirani niz snimiti u novi fajl u formatu kao u ulaznom fajlu.\r
+Ovo se najbolje testira tako sto se program ponovo pokrene i \r
+ucita se novonapravljeni fajl. Ako program normalno ucita i \r
+snimi podatke trebalo bi da je zadovoljen format.\r