summaryrefslogtreecommitdiffstats
path: root/inf/lige/1/2.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--inf/lige/1/2.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/inf/lige/1/2.c b/inf/lige/1/2.c
new file mode 100644
index 0000000..b961093
--- /dev/null
+++ b/inf/lige/1/2.c
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+int main (void) {
+ char buf[128];
+ fgets(buf, 128, stdin);
+ char * c = buf;
+ int n = strtol(c, &c, 10);
+ c++;
+ int k = strtol(c, &c, 10);
+ int * zx = calloc(1000000, sizeof *zx);
+ int * zy = calloc(1000000, sizeof *zy);
+ int x = 0;
+ int y = 0;
+ int num = 0;
+ int vseh = 0;
+ while (1) {
+ char a = getchar();
+ switch (a) {
+ case EOF:
+ goto x;
+ case '\r':
+ break;
+ case '\n':
+#ifndef EVAL
+ fprintf(stderr, "newline\n");
+#endif
+ if (num) {
+ zx[num-1] = x;
+ zy[num-1] = y;
+ num = 0;
+ vseh++;
+ }
+ x = 0;
+ y++;
+ break;
+ case ' ':
+#ifndef EVAL
+ fprintf(stderr, "presledek\n");
+#endif
+ if (num) {
+ zx[num-1] = x;
+ zy[num-1] = y;
+ num = 0;
+ vseh++;
+ }
+ x++;
+ break;
+ default:
+#ifndef EVAL
+ fprintf(stderr, "številka %c\n", a);
+#endif
+ num *= 10;
+ num += a - '0';
+ }
+ }
+x:;
+ long long int sum = 0;
+ int curx = 0;
+ int cury = 0;
+ for (int i = 0; i < vseh; i++) {
+ sum += abs(curx - zx[i]) + abs(cury - zy[i]);
+#ifndef EVAL
+ fprintf(stderr, "znamenitost %d je na %d %d, sum je %lld\n", i, zx[i], zy[i], sum);
+#endif
+ curx = zx[i];
+ cury = zy[i];
+ }
+ printf("%lld\n", sum);
+}