summaryrefslogtreecommitdiffstats
path: root/inf/lige/1/1.c
diff options
context:
space:
mode:
Diffstat (limited to 'inf/lige/1/1.c')
-rw-r--r--inf/lige/1/1.c50
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);
+}