1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}
|