From 775d3113cb90a3300eb2261842290f0884db420b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Fri, 18 Nov 2022 19:10:40 +0100 Subject: 1. liga zotks --- inf/lige/1/2.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 inf/lige/1/2.c (limited to 'inf/lige/1/2.c') 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 +#include +#include +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); +} -- cgit v1.2.3