summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-30 18:07:23 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-30 18:07:23 +0100
commit1189cb9910d18c894ffc99777d173f49bf961349 (patch)
treec157f49ea43e10cf84b4784deca6571573405620
parentaps1uni funkcije.c (diff)
parentdn08, tj.sh fixes subshell scope (diff)
downloadr-1189cb9910d18c894ffc99777d173f49bf961349.tar
r-1189cb9910d18c894ffc99777d173f49bf961349.tar.gz
r-1189cb9910d18c894ffc99777d173f49bf961349.tar.bz2
r-1189cb9910d18c894ffc99777d173f49bf961349.tar.lz
r-1189cb9910d18c894ffc99777d173f49bf961349.tar.xz
r-1189cb9910d18c894ffc99777d173f49bf961349.tar.zst
r-1189cb9910d18c894ffc99777d173f49bf961349.zip
-rw-r--r--.gitignore1
-rw-r--r--šola/p1/dn/DN08_63230317.java180
-rwxr-xr-xšola/p1/dn/tj.sh92
3 files changed, 231 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
index 039a515..524229a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ package-lock.json
vendor/
node_modules/
*.class
+javac.*.args
diff --git a/šola/p1/dn/DN08_63230317.java b/šola/p1/dn/DN08_63230317.java
new file mode 100644
index 0000000..86fca3f
--- /dev/null
+++ b/šola/p1/dn/DN08_63230317.java
@@ -0,0 +1,180 @@
+import java.util.*;
+public class DN08_63230317 {
+ static class Ulomek implements Comparable<Ulomek> {
+ private int števec;
+ private int imenovalec;
+ public Ulomek (int števec, int imenovalec) {
+ this.števec = števec;
+ this.imenovalec = imenovalec;
+ int gcd = this.gcd();
+ this.števec /= gcd;
+ this.imenovalec /= gcd;
+ }
+ private int celiDel () {
+ return this.števec/this.imenovalec;
+ }
+ private int gcd () {
+ return this.gcd(this.števec, this.imenovalec);
+ }
+ private static int gcd (int a, int b) {
+ if (b == 0)
+ return a;
+ return gcd(b, a%b);
+ }
+ public String toString () {
+ if (this.števec/this.gcd()-this.celiDel()*(this.imenovalec/this.gcd()) == 0)
+ return String.format("%d", this.celiDel());
+ return String.format("%d+%d/%d", this.celiDel(), this.števec/this.gcd()-this.celiDel()*(this.imenovalec/this.gcd()), this.imenovalec/this.gcd());
+ }
+ public Ulomek vsota (Ulomek a) {
+ return new Ulomek(this.števec*a.imenovalec+this.imenovalec*a.števec, this.imenovalec*a.imenovalec);
+ }
+ public Ulomek negacija () {
+ return new Ulomek(-this.števec, this.imenovalec);
+ }
+ public Ulomek produkt (Ulomek a) {
+ return new Ulomek(this.števec*a.števec, this.imenovalec*a.imenovalec);
+ }
+ public Ulomek obrat () {
+ return new Ulomek(this.imenovalec, this.števec);
+ }
+ @Override
+ public int compareTo (Ulomek b) {
+ return Integer.compare(this.števec*b.imenovalec, b.števec*this.imenovalec);
+ }
+ }
+ interface TočkeDela {
+ public Ulomek točk();
+ }
+ static class PrimerjalnikDel implements Comparator<Delo> {
+ @Override
+ public int compare (Delo prvi, Delo drugi) {
+ if (prvi.točk().compareTo(drugi.točk()) == 0)
+ return Integer.compare(drugi.vrstni_red, prvi.vrstni_red);
+ return prvi.točk().compareTo(drugi.točk());
+ }
+ }
+ abstract static class Delo implements TočkeDela {
+ String[] avtorji;
+ String naslov;
+ int vrstni_red;
+ Delo (Scanner sc, String jaz, int vrstni_red) {
+ this.vrstni_red = vrstni_red;
+ int avtorjev = sc.nextInt();
+ this.avtorji = new String[avtorjev];
+ for (int i = 0; i < avtorjev; i++) {
+ this.avtorji[i] = sc.next();
+ if (this.avtorji[i].equals("#"))
+ this.avtorji[i] = jaz;
+ }
+ this.naslov = sc.next();
+ }
+ }
+ private static class Monografija extends Delo {
+ String založba;
+ int leto;
+ String isbn;
+ public Monografija (Scanner sc, String jaz, int i) {
+ super(sc, jaz, i);
+ this.založba = sc.next();
+ this.leto = sc.nextInt();
+ this.isbn = sc.next();
+ }
+ public String toString () {
+ return String.format("%s: %s. %s %d, ISBN %s | %s", String.join(", ", Arrays.asList(avtorji)), naslov, založba, leto, isbn, točk().toString());
+ }
+ @Override
+ public Ulomek točk () {
+ return new Ulomek(10, 1).produkt(new Ulomek(avtorji.length, 1).obrat());
+ }
+ }
+ private static class Referat extends Delo {
+ boolean mednarodni;
+ String konferenca;
+ int začetna;
+ int končna;
+ public Referat (Scanner sc, String jaz, int i) {
+ super(sc, jaz, i);
+ this.konferenca = sc.next();
+ this.mednarodni = sc.nextBoolean();
+ this.začetna = sc.nextInt();
+ this.končna = sc.nextInt();
+ }
+ public String toString() {
+ return String.format("%s: %s. %s: %d-%d | %s", String.join(", ", Arrays.asList(avtorji)), naslov, konferenca, začetna, končna, točk().toString());
+ }
+ @Override
+ public Ulomek točk () {
+ Ulomek r = new Ulomek(1, 1);
+ if (this.mednarodni)
+ r = new Ulomek(3, 1);
+ return r.produkt(new Ulomek(avtorji.length, 1).obrat());
+ }
+ }
+ private static class Članek extends Delo {
+ int mestoRevije;
+ int številoRevij;
+ String revija;
+ int letnik;
+ int številka;
+ int leto;
+ int začetna;
+ int končna;
+ public Članek (Scanner sc, String jaz, int i) {
+ super(sc, jaz, i);
+ this.revija = sc.next();
+ this.letnik = sc.nextInt();
+ this.številka = sc.nextInt();
+ this.leto = sc.nextInt();
+ this.mestoRevije = sc.nextInt();
+ this.številoRevij = sc.nextInt();
+ this.začetna = sc.nextInt();
+ this.končna = sc.nextInt();
+ }
+ Ulomek impact () {
+ return new Ulomek(this.mestoRevije, this.številoRevij);
+ }
+ int kvartil () {
+ if (this.impact().compareTo(new Ulomek(1, 4)) != 1)
+ return 1;
+ if (this.impact().compareTo(new Ulomek(1, 2)) != 1)
+ return 2;
+ if (this.impact().compareTo(new Ulomek(3, 4)) != 1)
+ return 3;
+ if (this.impact().compareTo(new Ulomek(1, 1)) != 1)
+ return 4;
+ return 5;
+ }
+ public String toString () {
+ return String.format("%s: %s. %s %d(%d): %d-%d (%d) | %s", String.join(", ", Arrays.asList(avtorji)), naslov, revija, letnik, številka, začetna, končna, leto, točk().toString());
+ }
+ @Override
+ public Ulomek točk () {
+ Ulomek[] osnove = {null, new Ulomek(10, 1), new Ulomek(8, 1), new Ulomek(6, 1), new Ulomek(4, 1), new Ulomek(2, 1)};
+ return osnove[kvartil()].produkt(new Ulomek(avtorji.length, 1).obrat());
+ }
+ }
+ public static void main (String[] args) {
+ Scanner sc = new Scanner(System.in);
+ String jaz = sc.next();
+ int vnosov = sc.nextInt();
+ Delo[] dela = new Delo[vnosov];
+ for (int i = 0; i < vnosov; i++) {
+ String vrsta = sc.next();
+ switch (vrsta) {
+ case "monografija":
+ dela[i] = new Monografija(sc, jaz, i);
+ break;
+ case "referat":
+ dela[i] = new Referat(sc, jaz, i);
+ break;
+ case "clanek":
+ dela[i] = new Članek(sc, jaz, i);
+ break;
+ }
+ }
+ Arrays.sort(dela, new PrimerjalnikDel());
+ for (int i = dela.length-1; i >= 0; i--)
+ System.out.println(dela[i].toString());
+ }
+}
diff --git a/šola/p1/dn/tj.sh b/šola/p1/dn/tj.sh
index 4851ec6..ed9e510 100755
--- a/šola/p1/dn/tj.sh
+++ b/šola/p1/dn/tj.sh
@@ -6,51 +6,59 @@ d=$3
uspelih=0
napa=0
predolg=0
-ura=10s
-find $2 -name 'Test[0-9]*.java' -or -name '*.in' | while read -r f
-do
- echo -n "$f ... "
- uspeh=0
- if grep 'java$' <<<$f > /dev/null
- then
- stdout=`echo <(java $f)`
- else
- stdout=`echo <(java $1 < $f)`
- fi
- out=$(timeout $ura /usr/bin/time --quiet -f %E diff --ignore-trailing-space --side-by-side <(java `grep 'java$' <<<$f > /dev/null && echo $f || echo $1` <$f) `sed -e s/in$/out/ -e 's/Test\([0-9]\)/test\1/' -e s/java$/out/ <<<$f` 2>&1) && uspeh=1
- koda=$?
- if [ $uspeh -eq 0 ]
- then
- if [ $koda -eq 124 ]
+if [ x$URA = x ]
+then
+ ura=5s
+else
+ ura=$URA
+fi
+find $2 -name 'Test[0-9]*.java' -or -name '*.in' |
+{
+ while read -r f
+ do
+ echo -n "$f ... "
+ uspeh=0
+ if grep 'java$' <<<$f > /dev/null
then
- predolg=$(($predolg+1))
- echo "PREKORAČEN ČAS $ura!"
- if grep 'java$' <<<$f > /dev/null
- then
- true
- else
- echo "VHOD:"
- tac $f | tac
- fi
+ stdout=`echo <(java $f)`
else
- napa=$(($napa+1))
- echo "NAPAČEN IZHOD! Čas izvajanja: `tail -n1 <<<$out`"
- if grep 'java$' <<<$f > /dev/null
+ stdout=`echo <(java $1 < $f)`
+ fi
+ out=$(timeout $ura /usr/bin/time --quiet -f %E diff --ignore-trailing-space --side-by-side <(java `grep 'java$' <<<$f > /dev/null && echo $f || echo $1` <$f) `sed -e s/in$/out/ -e 's/Test\([0-9]\)/test\1/' -e s/java$/out/ <<<$f` 2>&1) && uspeh=1
+ koda=$?
+ if [ $uspeh -eq 0 ]
+ then
+ if [ $koda -eq 124 ]
then
- true
+ predolg=$(($predolg+1))
+ echo "PREKORAČEN ČAS $ura!"
+ if grep 'java$' <<<$f > /dev/null
+ then
+ true
+ else
+ echo "VHOD:"
+ tac $f | tac
+ fi
else
- echo "VHOD:"
- tac $f | tac
+ napa=$(($napa+1))
+ echo "NAPAČEN IZHOD! Čas izvajanja: `tail -n1 <<<$out`"
+ if grep 'java$' <<<$f > /dev/null
+ then
+ true
+ else
+ echo "VHOD:"
+ tac $f | tac
+ fi
+ echo "IZHOD: Levo je vaš izhod, desno je pravilen izhod:"
+ head -n-1 <<<$out
+ grep 'java$' <<<$f > /dev/null && echo -e "PRIPOROČILO: Če DN zahteva razrede (kot recimo DN06), morate imeti v trenutnem direktoriju PREVEDENE .class datoteke vaših zahtevanih razredov. Če so v katerem drugem direktoriju, morate nastaviti CLASSPATH.\nPoleg tega se lahko zgodi, da v direktoriju s testi obstaja TestSkupno.java (kot recimo DN07), ki ga je potrebno prevesti v z javac."
fi
- echo "IZHOD: Levo je vaš izhod, desno je pravilen izhod:"
- head -n-1 <<<$out
- grep 'java$' <<<$f > /dev/null && echo -e "PRIPOROČILO: Če DN zahteva razrede (kot recimo DN06), morate imeti v trenutnem direktoriju PREVEDENE .class datoteke vaših zahtevanih razredov. Če so v katerem drugem direktoriju, morate nastaviti CLASSPATH.\nPoleg tega se lahko zgodi, da v direktoriju s testi obstaja TestSkupno.java (kot recimo DN07), ki ga je potrebno prevesti v z javac."
+ else
+ uspelih=$(($uspelih+1))
+ echo "USPELO! Čas izvajanja: `tail -n1 <<<$out`"
fi
- else
- uspelih=$(($uspelih+1))
- echo "USPELO! Čas izvajanja: `tail -n1 <<<$out`"
- fi
-done
-echo "uspešnih testov: $uspelih"
-echo "napačnih izhodov: $napa"
-echo "prekoračen čas $ura: $predolg"
+ done
+ echo "uspešnih testov: $uspelih"
+ echo "napačnih izhodov: $napa"
+ echo "prekoračen čas $ura: $predolg"
+}