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/1.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/1.c')
-rw-r--r-- | inf/lige/1/1.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/inf/lige/1/1.c b/inf/lige/1/1.c new file mode 100644 index 0000000..8bbfdaa --- /dev/null +++ b/inf/lige/1/1.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +int main () { + int debug = 0; + char buf[128]; + char buf2[128]; + fgets(buf, 128, stdin); + char * x = buf; + int m = strtol(x, &x, 10); + x++; + int n = strtol(x, NULL, 10); + if (debug) fprintf(stderr, "m %d n %d\n", m, n); + char * old = buf; + char * cur = buf2; + memset(old, '0', 128); + memset(cur, '0', 128); + unsigned mej = 0; + while (!ferror(stdin) && !feof(stdin) && m--) { + fgets(cur, 128, stdin); + unsigned meja = 0; + for (int i = 0; i < n-1; i++) + if (cur[i] != cur[i+1]) + meja++; + if (cur[n-1] == '1') + meja++; + if (cur[0] == '1') + meja++; + if (debug) fprintf(stderr, "vrsta. po ld je mej: %u\n", meja); + mej += meja; + meja = 0; + for (int i = 0; i < n; i++) + if (old[i] != cur[i]) + meja++; + if (debug) fprintf(stderr, "\tpo gor dol je mej: %u\n", meja); + mej += meja; + meja = 0; + if (!m) + for (int i = 0; i < n; i++) + if (cur[i] == '1') + meja++; + if (debug) fprintf(stderr, "\tpo zadnji je mej: %u\n", meja); + mej += meja; + meja = 0; + char * tmp = old; + old = cur; + cur = tmp; + } + printf("%u\n", mej); +} |