diff options
author | sijanec <anton@sijanec.eu> | 2021-01-15 08:22:07 +0100 |
---|---|---|
committer | sijanec <anton@sijanec.eu> | 2021-01-15 08:22:07 +0100 |
commit | 2057a987a330e086659a9bf95fa69cf168f861a3 (patch) | |
tree | c316b35c9562ec2c8a513ae9cb364d5a32833663 /inf/rtk/offline | |
parent | 22. domača naloga za matematiko (diff) | |
download | sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.tar sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.tar.gz sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.tar.bz2 sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.tar.lz sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.tar.xz sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.tar.zst sola-gimb-2-2057a987a330e086659a9bf95fa69cf168f861a3.zip |
Diffstat (limited to 'inf/rtk/offline')
-rw-r--r-- | inf/rtk/offline/.gitignore | 4 | ||||
-rw-r--r-- | inf/rtk/offline/Makefile | 23 | ||||
-rw-r--r-- | inf/rtk/offline/npk.c | 60 | ||||
-rw-r--r-- | inf/rtk/offline/offline.h | 8 | ||||
-rw-r--r-- | inf/rtk/offline/origprog.c | 78 | ||||
-rw-r--r-- | inf/rtk/offline/razdeli.c | 65 | ||||
-rw-r--r-- | inf/rtk/offline/resi.c | 67 | ||||
-rw-r--r-- | inf/rtk/offline/test.txt | 2 |
8 files changed, 0 insertions, 307 deletions
diff --git a/inf/rtk/offline/.gitignore b/inf/rtk/offline/.gitignore deleted file mode 100644 index ffeb5c9..0000000 --- a/inf/rtk/offline/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -stiskanje-unix.in -stiskanje.in -naloge/ -*.out diff --git a/inf/rtk/offline/Makefile b/inf/rtk/offline/Makefile deleted file mode 100644 index dde543e..0000000 --- a/inf/rtk/offline/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -default: - @echo "offline naloga in rešitev za ijs.rtk. recepti:" - @echo "- make prepare: prenese datoteke, potrebne za nalogo" - @echo "- make razdeli: razdeli naloge v posamezne datoteke" - @echo "- make npk: naredi program za najdaljši ponavljajoči kos" - @echo "- make resi: naredi program za reševanje" - -prepare: - wget http://rtk.ijs.si/2020/stiskanje/stiskanje-unix.in -c - wget http://rtk.ijs.si/2020/stiskanje/stiskanje.in -c - -resi: - gcc -Wall -pedantic -I. -g -oresi.out resi.c - -npk: - gcc -Wall -pedantic -I. -g -onpk.out npk.c - -razdeli: - gcc -Wall -pedantic -I. -g -orazdeli.out razdeli.c - ./razdeli.out < stiskanje-unix.in - rm -rf naloge - mkdir -p naloge - mv naloga*.txt naloge/ diff --git a/inf/rtk/offline/npk.c b/inf/rtk/offline/npk.c deleted file mode 100644 index a18b38a..0000000 --- a/inf/rtk/offline/npk.c +++ /dev/null @@ -1,60 +0,0 @@ -#if __INCLUDE_LEVEL__ != 0 -#pragma once -#endif -/* najdaljši ponavljajoči kos niza */ -#include <stdio.h> -#include <stdlib.h> -#include <offline.h> -#include <string.h> -/* lahko bi šli čez niz znakov for(strlen)for(strlen)for(strlen), ampak to - * bi trajalo zelo dolgo, čas*1000000^3 in bi imelo O(n^3) kompleksnost. - * ta implementacija najde najdaljši string in ima kompleksnost - * PRIBLIŽNO OKOLI O(n^2), kar je bistveno hitreje, PRIBLIŽNO čas*1000000^2. */ -struct rtk_kos npk (char * s) { - struct rtk_kos k; - k.l = 0; k.o = 0; - const size_t l = strlen(s); - unsigned char ** z = calloc(l+1, sizeof(unsigned char *)); - size_t i = 0; - size_t j = 0; - for (i = 0; i < l+1; i++) - z[i] = calloc(l+1, sizeof(unsigned char)); - for (i = 1; i <= l; i++) - for (j = i+1; j <= l; j++) - if (s[i-1] == s[j-1] && z[i-1][j-1] < (j-1)) { - z[i][j] = z[i-1][j-1] + 1; - if (z[i][j] > k.l) { - k.l = z[i][j]; - k.o = k.o > i ? k.o : i; - } - } else - z[i-1][j-1] = 0; - k.o = k.o-k.l; - for (i = 0; i < l+1; i++) { - free(z[i]); z[i] = NULL; - } - free(z); - z = NULL; - return k; -} -#if __INCLUDE_LEVEL__ == 0 -int main (int argc, char ** argv) { - char c = getchar(); - size_t v = 0; - char * s = malloc(sizeof(char)*1); - struct rtk_kos k; - while (!feof(stdin)) { - s = realloc(s, sizeof(char)*v+2); - s[v++] = c; - s[v] = '\0'; - c = getchar(); - } - k = npk(s); - for (v = 0; v < k.l; v++) - putchar(s[v+k.o]); - putchar('\n'); /* za dobro mero */ - free(s); - s = NULL; - return 0; -} -#endif diff --git a/inf/rtk/offline/offline.h b/inf/rtk/offline/offline.h deleted file mode 100644 index 9724846..0000000 --- a/inf/rtk/offline/offline.h +++ /dev/null @@ -1,8 +0,0 @@ -#define RTK_EOL '\r' -#define RTK_IDC(x,y) (x/y + (x % y != 0)) /* int devide ceil */ -#define RTK_RAM_KOS 128 -struct rtk_kos { - size_t o; /* ffset */ - size_t l; /* ength */ - size_t p; /* ojavi */ -}; diff --git a/inf/rtk/offline/origprog.c b/inf/rtk/offline/origprog.c deleted file mode 100644 index 631d61d..0000000 --- a/inf/rtk/offline/origprog.c +++ /dev/null @@ -1,78 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <offline.h> -size_t rtk_resi (/* const */ char * s, struct rtk_kos * p) { - size_t i = 0; - size_t j = 0; - size_t k = 0; - size_t l = strlen(s); - size_t p_sizeof = RTK_RAM_KOS; size_t pzi = 0; /* pieces za izdelavo */ - size_t pjev = 0; size_t psd = 0; /* pieces sigma dolžin */; - /* struct rtk_kos * */ p = malloc(sizeof(struct rtk_kos)*p_sizeof); - /* začnemo s preprosto rešitvijo: en kos, celoten niz */ - p[0].o = 0; p[0].l = l; p[0].p = 1; pjev++; psd = l; pzi = 1; - /* iščemo ponovitve za izboljšavo, začnemo z dolžino 2 */ - /* kosov, velikih 1, še ne potrebujemo */ - /* POMNI: izračun točk: psd+pzi */ - for (i = 2; i < l; i++) { /* za vsako možno dolžino kosa */ - for (j = 0; j < l-i; j++) { /* za vsako lokacijo, kjer bi se začel kos */ - // fprintf(stderr, "%.*s\n", i, s+j); - } - } - return pjev; -} -int main (int argc, char ** argv) { - char ** n = malloc(sizeof(char *) * 1); - size_t * v = malloc(sizeof(size_t) * 1); - size_t nalog = 0; - int returnstatus = 0; - char c = getchar(); - int vrs = 0; - size_t pjev; - char fn[69]; - FILE * fd; - struct rtk_kos * p; - n[0] = NULL; - v[0] = 0; - while (!feof(stdin)) { - n[nalog] = realloc(n[nalog], sizeof(char)*v[nalog]+2); - n[nalog][v[nalog]++] = c; - n[nalog][v[nalog]] = '\0'; - if (c == RTK_EOL) { - if (vrs == 0 && strncmp("Stiskanje", n[0], strlen("Stiskanje") != 0)) { - fprintf(stderr, "vhodna datoteka se ne začne s \"Stiskanje\"\n"); - returnstatus = 1; - goto returncleanly; - } - if ((vrs - 2) % 3 == 2) { /* če je bila to naloga */ - fprintf(stderr, "prepisal nalogo %lu\r", nalog); - nalog++; - n = realloc(n, sizeof(char*)*(nalog+1)); - n[nalog] = NULL; - v = realloc(v, sizeof(size_t)*(nalog+1)); - } - v[nalog] = 0; /* gremo na začetek prostora za nalogo */ - vrs++; - } - c = getchar(); - } - fprintf(stderr, "zapisal naloge v spomin. \n"); - for (vrs = 0; vrs < nalog; vrs++) { - fprintf(stderr, "rešujem nalogo %d\n", vrs); - pjev = rtk_resi(n[vrs], p); - free(p); - p = NULL; - } - returncleanly: - while (nalog > 0) { - nalog--; - free(n[nalog]); - n[nalog] = NULL; - } - free(n); - n = NULL; - free(v); - v = NULL; - return returnstatus; -} diff --git a/inf/rtk/offline/razdeli.c b/inf/rtk/offline/razdeli.c deleted file mode 100644 index 24c36c1..0000000 --- a/inf/rtk/offline/razdeli.c +++ /dev/null @@ -1,65 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <offline.h> -int main (int argc, char ** argv) { - char ** n = malloc(sizeof(char *) * 1); - size_t * v = malloc(sizeof(size_t) * 1); - size_t nalog = 0; - int returnstatus = 0; - char c = getchar(); - int vrs = 0; - size_t pjev; - char fn[69]; - FILE * fd; - /* struct rtk_kos * p; */ - n[0] = NULL; - v[0] = 0; - while (!feof(stdin)) { - n[nalog] = realloc(n[nalog], sizeof(char)*v[nalog]+2); - n[nalog][v[nalog]++] = c; - n[nalog][v[nalog]] = '\0'; - if (c == RTK_EOL) { - if (vrs == 0 && strncmp("Stiskanje", n[0], strlen("Stiskanje") != 0)) { - fprintf(stderr, "vhodna datoteka se ne začne s \"Stiskanje\"\n"); - returnstatus = 1; - goto returncleanly; - } - if ((vrs - 2) % 3 == 2) { /* če je bila to naloga */ - n[nalog][--v[nalog]] = '\0'; - fprintf(stderr, "prepisal nalogo %lu\r", nalog); - nalog++; - n = realloc(n, sizeof(char*)*(nalog+1)); - n[nalog] = NULL; - v = realloc(v, sizeof(size_t)*(nalog+1)); - } - v[nalog] = 0; /* gremo na začetek prostora za nalogo */ - vrs++; - } - c = getchar(); - } - fprintf(stderr, "zapisal naloge v spomin. \n"); - for (vrs = 0; vrs < nalog; vrs++) { - fprintf(stderr, "shranjujem nalogo %d\n", vrs); - snprintf(fn, 69, "naloga%d.txt", vrs+1); - fd = fopen(fn, "w"); - pjev = 0; - while (n[vrs][pjev] != '\0') - putc(n[vrs][pjev++], fd); - fprintf(stderr, "zadnji znak je %02x\n", n[vrs][--pjev]); - fclose(fd); - /* pjev = rtk_resi(n[vrs], p); - free(p); */ - } - returncleanly: - while (nalog > 0) { - nalog--; - free(n[nalog]); - n[nalog] = NULL; - } - free(n); - n = NULL; - free(v); - v = NULL; - return returnstatus; -} diff --git a/inf/rtk/offline/resi.c b/inf/rtk/offline/resi.c deleted file mode 100644 index 43f97cc..0000000 --- a/inf/rtk/offline/resi.c +++ /dev/null @@ -1,67 +0,0 @@ -#if __INCLUDE_LEVEL__ != 0 -#pragma once -#endif -/* najdaljši ponavljajoči kos niza */ -#include <stdio.h> -#include <stdlib.h> -#include <offline.h> -#include <string.h> -#define RTK_NAENKRAT 60000 -/* lahko bi šli čez niz znakov for(strlen)for(strlen)for(strlen), ampak to - * bi trajalo zelo dolgo, čas*1000000^3 in bi imelo O(n^3) kompleksnost. - * ta implementacija najde najdaljši string in ima kompleksnost - * PRIBLIŽNO OKOLI O(n^2), kar je bistveno hitreje, PRIBLIŽNO čas*1000000^2. */ -struct rtk_kos npk (const char * s, const size_t l) { - struct rtk_kos k; - k.l = 0; k.o = 0; - unsigned char ** z = calloc(l+1, sizeof(unsigned char *)); - size_t i = 0; - size_t j = 0; - for (i = 0; i < l+1; i++) - z[i] = calloc(l+1, sizeof(unsigned char)); - for (i = 1; i <= l; i++) - for (j = i+1; j <= l; j++) - if (s[i-1] == s[j-1] && z[i-1][j-1] < (j-1)) { - z[i][j] = z[i-1][j-1] + 1; - if (z[i][j] > k.l) { - k.l = z[i][j]; - k.o = k.o > i ? k.o : i; - } - } else - z[i-1][j-1] = 0; - k.o = k.o-k.l; - for (i = 0; i < l+1; i++) { - free(z[i]); z[i] = NULL; - } - free(z); - z = NULL; - return k; -} -#if __INCLUDE_LEVEL__ == 0 -int main (int argc, char ** argv) { - char c = getchar(); - size_t v = 0; - char * s = malloc(sizeof(char)*1); - struct rtk_kos k1; - struct rtk_kos k2; - size_t l = 0; - while (!feof(stdin)) { - s = realloc(s, sizeof(char)*v+2); - s[v++] = c; - s[v] = '\0'; - c = getchar(); - } - l = v; - for (v = 0; v*RTK_NAENKRAT <= l;) { - k1 = npk(s+(v*(RTK_NAENKRAT/2)), RTK_NAENKRAT); - k2 = npk(s+(++v*(RTK_NAENKRAT/2)), RTK_NAENKRAT); - } - - for (v = 0; v < k.l; v++) - putchar(s[v+k.o]); - putchar('\n'); /* za dobro mero */ - free(s); - s = NULL; - return 0; -} -#endif diff --git a/inf/rtk/offline/test.txt b/inf/rtk/offline/test.txt deleted file mode 100644 index 139597f..0000000 --- a/inf/rtk/offline/test.txt +++ /dev/null @@ -1,2 +0,0 @@ - - |