summaryrefslogtreecommitdiff
path: root/1.4/combo.c
diff options
context:
space:
mode:
Diffstat (limited to '1.4/combo.c')
-rw-r--r--1.4/combo.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/1.4/combo.c b/1.4/combo.c
new file mode 100644
index 0000000..7c5b3d1
--- /dev/null
+++ b/1.4/combo.c
@@ -0,0 +1,51 @@
+/*
+ID: mytbk921
+LANG: C
+TASK: combo
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int matches(int a[], int b[], int N)
+{
+ int i;
+ for (i = 0; i < 3; i++) {
+ if (abs(a[i]-b[i]) <= 2 ||
+ N - abs(a[i]-b[i]) <= 2)
+ continue;
+ else
+ return 0;
+ }
+ return 1;
+}
+
+int main()
+{
+ FILE *fin, *fout;
+ int farmer[3], master[3], test[3];
+ int N, i, count = 0;
+
+ fin = fopen("combo.in", "r");
+ fout = fopen("combo.out", "w");
+
+ fscanf(fin, "%d", &N);
+ for (i = 0; i<3; i++)
+ fscanf(fin, "%d", &farmer[i]);
+ for (i = 0; i<3; i++)
+ fscanf(fin, "%d", &master[i]);
+ fclose(fin);
+
+ for (test[0] = 1; test[0] <= N; test[0]++)
+ for (test[1] = 1; test[1] <= N; test[1]++)
+ for (test[2] = 1; test[2] <= N; test[2]++)
+ if (matches(farmer, test, N) || matches(master, test, N))
+ count++;
+
+ fprintf(fout, "%d\n", count);
+ fclose(fout);
+ return 0;
+}
+
+