diff options
Diffstat (limited to 'inf/rtk/2021-izbirno/1/prog.c')
-rw-r--r-- | inf/rtk/2021-izbirno/1/prog.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/inf/rtk/2021-izbirno/1/prog.c b/inf/rtk/2021-izbirno/1/prog.c new file mode 100644 index 0000000..aa3e62d --- /dev/null +++ b/inf/rtk/2021-izbirno/1/prog.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +int main (int argc, char ** argv) { + char * buf = malloc(500); + fgets(buf, 500, stdin); + char * cp; + int n = strtoll(buf, &cp, 10); + cp++; + int k = strtoll(cp, NULL, 10); + int * a = calloc(n+1, sizeof(int)); + int * t = calloc(n+1, sizeof(int)); /* t[x] = ekipa št <od 1 do k> */ + realloc(buf, (n+1)*6); + fgets(buf, (n+1)*6, stdin); + cp = buf; + int i = 0; /* i bo število zadnjega in hkrati število vseh, kajti prvi je 1 */ + do { + int ai = strtoll(cp, &cp, 10); + if (ai != 0) + a[++i] = ai; + cp++; + } while (cp[-1] != 0 && cp[-1] != '\n' && cp[-1] != '\r'); + if (i != n) + fprintf(stderr, "error %d ni %d\n", n, i); + int ze = 0; /* referencaj novo ekipo po (++ze % k)+1 */ +k1: + for (int j = 1; j <= n; j++) { + if (!t[(i = j)]) + goto k2; + } + goto konec; +k2: + /* + e = 0; + while (!t[zn]) { + if (!e++) + fprintf(stdout, "%d ", zn); + if (t[a[zn]]) { // če je naš a že v ekipi, i damo v to ekipo + t[zn] = t[a[zn]]; + zn++; + } + t[zn] = (ze % k)+1; + zn = a[zn]; + } + ze++; + */ + if (ze) + fprintf(stdout, " "); + fprintf(stdout, "%d", i); + t[i] = ++ze; +k3: + if (t[a[i]]) + goto k1; +k4: + i = a[i]; +k5: + t[i] = ze; + goto k3; +konec: + fprintf(stdout, "\n"); + free(buf); + return 0; +} |