From fe9f8b1bdde07a564e9097e4b2bb433634690983 Mon Sep 17 00:00:00 2001 From: sijanec Date: Thu, 11 Feb 2021 18:01:40 +0100 Subject: kar sram me je tole v git objavit tbh --- inf/zotks/3/prog.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 inf/zotks/3/prog.c (limited to 'inf/zotks/3/prog.c') diff --git a/inf/zotks/3/prog.c b/inf/zotks/3/prog.c new file mode 100644 index 0000000..4b6b551 --- /dev/null +++ b/inf/zotks/3/prog.c @@ -0,0 +1,49 @@ +#include +#include +#include +int main (int argc, char ** argv) { + size_t k[200000]; + char b[2000000]; + size_t d = 0; + char * p = NULL; + char ne[128]; + char * nu = fgets(ne, 127, stdin); + nu++; nu--; + size_t n = strtoll(ne, NULL, 10); + char c = fgetc(stdin); + while (!feof(stdin)) { + b[d++] = c; + c = fgetc(stdin); + } + if (b[d-1] == '\n') /* ce je input slucajno koncan z EOL */ + d--; + if (b[d-1] == '\r') /* ce se slucajno uporablja slab operacijski sistem */ + d--; + b[d] = '\0'; + d = 0; + p = b; + do { + k[d] = strtol(p, &p, 10); + p++; /* sizeof(char) je itak 1 */ + d++; + } while (p[-1] != '\0'); + d; + size_t korakov = 0; + size_t temp = 0; + for (long int zz = 0; zz < d; zz++) { + /* fprintf(stderr, "%lu %lu %lu %lu %lu\n", k[0], k[1], k[2], k[3], k[4]); */ + if (k[zz] == zz+1) { + korakov++; + temp = k[0]; + memcpy(&(k[0]), &(k[1]), sizeof(size_t)*(d-1)); + k[d-1] = temp; + zz = -1; + } + if (korakov >= d) { + fprintf(stdout, "-1\n"); + return 0; + } + } + fprintf(stdout, "%lu\n", korakov); + return 0; +} -- cgit v1.2.3