diff options
Diffstat (limited to 'inf/zotks/3/prog.c')
-rw-r--r-- | inf/zotks/3/prog.c | 49 |
1 files changed, 49 insertions, 0 deletions
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 <stdlib.h> +#include <stdio.h> +#include <string.h> +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; +} |