diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-11-18 19:10:40 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-11-18 19:10:40 +0100 |
commit | 775d3113cb90a3300eb2261842290f0884db420b (patch) | |
tree | 9181e6585cb6a0429ed736c6069f8c7f87f5cc19 /inf/lige/1/2.c | |
parent | nekaj matematike (diff) | |
download | sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.tar sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.tar.gz sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.tar.bz2 sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.tar.lz sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.tar.xz sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.tar.zst sola-gimb-4-775d3113cb90a3300eb2261842290f0884db420b.zip |
Diffstat (limited to 'inf/lige/1/2.c')
-rw-r--r-- | inf/lige/1/2.c | 70 |
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); +} |